In Unity 5, I started noticing that when I open a project, it’s hierarchy has been almost completely jumbled, the only thing I can rely on is parent/child relationships. This hasn’t been a problem for a while, as order in the hierarchy doesn’t matter unless you look for children by index.
Unity UI layers it’s elements based on it’s order in the hierarchy. Every time I open my project, my UI layering is completely ruined by the randomly jumbled hierarchy! Words cannot describe how frustrating this is.
I cannot report a bug that includes files from my project because I don’t own the project. This can be replicated in any Unity 5 project with a full enough hierarchy.
Well I assure you it happens, it’s reported by lots of people (check the issue tracker).
To top it off, I’ve discovered today that your hierarchy can rearrange itself when you enter play mode. I even tried saving the scene and project before hitting play, and I can sit there and hit play, stop, play, stop over and over and watch the hierarchy jumble back and forth between the order I gave it and the order it decided upon.
This is no longer a problem for me because I made a special script to save the hierarchy order at edit-time and force it at load-time. It was complicated and took me several hours and required a lot of editor scripting, which most users don’t know how to write. This is a really bad bug that needs to be fixed… I don’t see how those learning to program can possibly overcome this without awkward parenting, which in a way teaches them bad design habits.
I don’t know if this helps given that I think there is more than one cause of this issue, but I saw this happen where an object refused to keep its position in hierarchy when you hit play. The object in question was a prefab. I discovered that when I broke the connection with the prefab for that object, it fixed the problem.
Good find, but it’s not always an acceptable solution when you need to keep 4 sections of UI using the same prefab, each with their own subtle changes and still have correct layering (like every split-screen game…)
Just noticed this happening with a UI panel with two children, an image and text. On play the two children change order so now the text is on top of the image. I’m forcing it with setaslastsibling() but this is just annoying.
From some quick debugging it looks like the Sibling Index is in fact changing, and I am not changing it, unless it is a knock on effect of something else. Thing is that it is already “wrong” at the time of Awake, so I don’t even see a way to work around it!
Also noticing as pointed out by RV1 that if I break the prefabs, then the problem goes away. Not a real solution though for many reasons, not the least of which going through an entire UI and breaking all the prefabs is painful as you have to delete a child to break it then re-add that child.
I have a editor tool that I use to bulk apply properties to objects based on data loaded form JSON. I run this in the editor and it updates thing. Suddenly I noticed that they were losing those properties upon loading the scene or hitting play. On a whim, I broke the prefab and reloaded the properties and then bam they were persisting properly again. I bet this is why the sibling index is getting reset as well.
Does anyone know if this bug is fixed? My prefabs reorder in hierarchy when I press play. Is there any other workaround than disconnecting with the prefab?