SuperTiled2Unity icon indicating copy to clipboard operation
SuperTiled2Unity copied to clipboard

Bug/Problem: When instantiating prefabs in custom importer and attaching them to the imported map, all children get sorted alphabetically

Open SharlatanY opened this issue 6 years ago • 10 comments

Ok, this might be a bit hard to explain, but let me try my best:

When you have a custom importer and instantiate a prefab in that importer, then attach the prefab to the map or a child of the map, like a layer (really doesn't matter on which hierarchy level), all the prefab's children get alphabetically.

I described why this is a problem for UI prefabs here, where I wasn't thinking too clearly and first thought, it might be a Unity bug, without debugging thins better before posting: https://forum.unity.com/threads/solved-prefab-instantiation-bug-in-2018-3-maybe-sooner-children-get-sorted-alphabetically.601429/#post-4022794

To replicate, I made a small demo project you can get here: https://drive.google.com/open?id=13bbs0CUfcYeZx20OU8vNMHMYm4Opcd6F

I'm using Unity 2018.3.0f2, btw.

In this project you can find the following things.:

  • The prefab TestPrefab: Prefab that contains a canvas with two panels, a back panel and a front panel. In the prefab, the front panel comes after the back panel hierarchically, thus obstructing the back panel. However, the panels are named in such a way that the back panel will obstruct the front panel, when sorted alphabetically.
  • The custom PrefabInstantiationImporter-importer. This importer creates an instance of TestPrefab and adds it to the map.
  • The scene SampleScene, which is used to demonstrate the problem

SampleScene contains the following noteworthy elements:

  • A TestOvehad map prefab. The map also already has set the custom importer. As you can see in the children of the TestPrefab(Clone)-object, which itself is now a child of the map prefab, all the children are sorted alphabetically. This will stay the same, when you reimport the map. As you can see when running the scene, the back panel is now obstructing the front panel.
  • A disabled GameObject named "PrefabInstantiator". When you enable this object and start the scene, the object has a script attached that will make an instance of TestPrefab and add it to the scene. If you look at that instance, you'll notice that the children of the prefab weren't reordered alphabetically, which is the desired behavior.

Feel free to ask if you have any questions!

Thanks a lot for your support and have a nice weekend!

SharlatanY avatar Dec 21 '18 10:12 SharlatanY

Hi again, @SharlatanY. This appears to be a bug with Unity's scripted importer. I've simplified your example down to a small number of files (with no SuperTiled2Unity) and entered a bug against it.

I'll keep this issue updated with progress on that bug report. You can also follow it here.

Thanks.

Seanba avatar Dec 22 '18 18:12 Seanba

Hi @Seanba ! Thank you very much! I can't tell you enough how much I appreciate all the effort you put in!

When I found out it only happens in the importer and not when instantiating a prefab "the normal way", I spent an hour or so going through your code, trying to figure where you possibly could sort the objects alphabetically but couldn't find anything. But I assumed I just didnt't understand your code well enough an was overlooking something. That's why I opened this issue instead of directly creating a bug with Unity. Hope, at least the demo project saved you some time!

Have a nice wekend and again: Thank you so, so much for all your effort!

SharlatanY avatar Dec 22 '18 19:12 SharlatanY

@SharlatanY, I figured it was a bug on my side too. In some ways I wish it were so as I could fix the issue without being dependent on the Unity guys but hopefully they'll provide an update soon. Thanks and happy holidays.

Seanba avatar Dec 23 '18 01:12 Seanba

Thanks again and happy holidays to you too!

SharlatanY avatar Dec 23 '18 14:12 SharlatanY

Update: Unity had told me a fix for this was coming but as of 2019.1.0f2 it is still an issue. Unfortunately they closed the bug on me so I'm not able to track any progress.

seanb-22ct avatar Apr 22 '19 19:04 seanb-22ct

Thanks for the effort and the update anyway, it's highly appreciated! Let's hope they fix it soon. Shame they couldn't give you a link to the other issue it seems to be a duplicate of. Hope, they're still tracking it.

Have a great week!

SharlatanY avatar Apr 22 '19 20:04 SharlatanY

This is still an issue with Unity 2010.2.8. I have reached out to Unity QA in hopes of getting an update. Thanks.

Seanba avatar Oct 09 '19 23:10 Seanba

Quick update: Unity tells me the fix they put in for Unity 2019.2.0a5 was actually for the ModelImporter class. They have re-opened my bug and have sent it to their ScriptedImporter team for a further look.

Seanba avatar Oct 27 '19 04:10 Seanba

Thank you for keeping me in the loop and in contact with Unity!

SharlatanY avatar Nov 04 '19 19:11 SharlatanY

Hi again, @SharlatanY. Sorry to report that this is still an issue with Unity's scripted importers in version 2020.2. The Unity team has made a significant number of changes to scripted importers so I was hoping they would have fixed this by now but sadly that's not the case.

Seanba avatar Jan 02 '21 04:01 Seanba