We’re additively loading scenes (via Addressables) and the order of game objects in the hierarchy becomes inverted, so that what was at the top of the hierarchy is now at the bottom. Everything completely in inverse order.
Is there anything that controls or causes this to happen?
We’re working with in 2D with an orthographic camera, I believe it is causes some of our UI objects to become hidden,
I don’t think it could directly be, except if your scene was ambiguous about sorting order or z depth to begin with.
Also, the order of root objects in scene are not stable or guaranteed in any way.
But to solve your sorting problem, here’s what I know:
Three (3) ways that Unity draws / stacks / sorts / layers / overlays stuff:
https://discussions.unity.com/t/841904/2
In short,
-
The default 3D Renderers draw stuff according to Z depth - distance from camera.
-
SpriteRenderers draw according to their Sorting Layer and Sorting Depth properties
-
UI Canvas Renderers draw in linear transform sequence, like a stack of papers
If you find that you need to mix and match items using these different ways of rendering, and have them appear in ways they are not initially designed for, you need to:
- identify what you are using
- search online for the combination of things you are doing and how to to achieve what you want.
There may be more than one solution to try.
Additional reading in the official docs:
https://docs.unity3d.com/Manual/2DSorting.html
And SortingGroups can also be extremely helpful in certain circumstances:
https://docs.unity3d.com/Manual/class-SortingGroup.html
Hey thanks for your reply! Yes, I am intimately familiar with all of those resources and methods of sorting UI images and sprites.
I got to this point trying to track down a nefarious problem where in our iOS build we have 1 UI image that appears as it should but in our OS X Desktop build from the exact same project the image is not visible. The image is in a Prefab with its own canvas I have yet to get a report from our testers about the image visibility in Android and Windows builds,
I began to suspect that the two build outputs do not sort in the same way, and then I discovered this hierarchy inversion, which seems like a clue.
Unfortunately there are a few “hierarchy not saved” bugs around in the Unity issue tracker, e.g.
But I never encountered a full “hierarchy gets reversed” issue! Which version of the Editor are you on?
Are you sure there’s nothing in code that does it perhaps - maybe searching the entire project for SetAsFirstSibling, SetAsLastSibling or SetSiblingIndex could give a clue.