Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Scene hierarchy becomes inverted in loaded scene?

Discussion in 'Editor & General Support' started by streeetwalker, Sep 14, 2022.

  1. streeetwalker


    Jun 4, 2013
    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,
  2. Kurt-Dekker


    Mar 16, 2013
    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:

    In short,

    1. The default 3D Renderers draw stuff according to Z depth - distance from camera.

    2. SpriteRenderers draw according to their Sorting Layer and Sorting Depth properties

    3. 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:

    And SortingGroups can also be extremely helpful in certain circumstances:
  3. streeetwalker


    Jun 4, 2013
    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.
  4. evyatron


    Jul 20, 2014
    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.