- Home /
How To Sort Prefabs In Hierarchy?
Hello, I have added several of the same prefab object into the hierarchy. Even if I reorder the hierarchy, when play is pressed, it reorders everything back to the creation order. Is there a way to stop or address this default behavior?
E.g.
Creation order:
Hierarchy
Prefab (0)
Prefab (1)
Prefab (2)
After reorder:
Hierarchy
Prefab (2)
Prefab (0)
Prefab (1)
When play is pressed:
Hierarchy
Prefab (0)
Prefab (1)
Prefab (2)
Thanks for the help!
I fail to understand why is this even an issue for you? Is not like your users can see this hierarchy anyways. Why is this an issue to the game play? I have done board games with tiles, and I usually make a folder for all tiles. The tiles are created by an for loop. I guess you could also do the same if this is so important to you. $$anonymous$$ake a for loop and instantiate game objects in the order you want, I wanna say you will also need the location in the world for each object.
Sorting in hierarchy is important when there is a layout group. First prefab shows up first in the list. The ability to be able to sort them in the hierarchy by script would be a lot useful!
Answer by konsnos · Aug 22, 2016 at 11:42 AM
http://docs.unity3d.com/ScriptReference/Transform.GetSiblingIndex.html
to get the index in the hierarchy of a gameobject comparing to its parent and
http://docs.unity3d.com/ScriptReference/Transform.SetSiblingIndex.html
to set it's place in it.