Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Hierarchy rearranges itself

Discussion in 'UGUI & TextMesh Pro' started by MSplitz-PsychoK, Nov 4, 2015.

  1. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    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.
     
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
  3. Deleted User

    Deleted User

    Guest

    I've personally never noticed this and use Unity every day at work.
     
  4. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    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.

    http://issuetracker.unity3d.com/issues/hierarchy-reorders-itself-when-entering-playmode
    http://issuetracker.unity3d.com/iss...ot-saved-when-scene-is-reloaded-slash-started
    http://issuetracker.unity3d.com/issues/hierarchy-order-of-canvas-children-is-not-persistent (claims it's fixed, but I can still reproduce in 5.1.3f)
     
    Last edited: Nov 6, 2015
  5. Sebioff

    Sebioff

    Joined:
    Dec 22, 2013
    Posts:
    218
    I'm experiencing it too ever since upgrading to 5.2, had no problems with 5.1.
     
  6. Stone-Legion

    Stone-Legion

    Joined:
    Aug 16, 2013
    Posts:
    112
  7. RV1

    RV1

    Joined:
    Nov 18, 2012
    Posts:
    68
    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.
     
  8. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    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....)
     
  9. Sebioff

    Sebioff

    Joined:
    Dec 22, 2013
    Posts:
    218
    In my scene it's happening with objects that aren't prefabs.
     
    Stone-Legion likes this.
  10. AshyB

    AshyB

    Joined:
    Aug 9, 2012
    Posts:
    191
    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.
     
  11. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    Having this happen right now in 5.6 and it is killing me! Every time I hit play my Canvas hierarchy gets re-arranged!
     
  12. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    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!
     
  13. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    Actually I don't even have to hit play. Just load the scene and it gets messed up!
     
  14. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    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.
     
  15. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    Bingo! Prefabs aren't properly serializing/deserializing!

    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.
     
  16. Botilada

    Botilada

    Joined:
    Apr 25, 2019
    Posts:
    8
    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?
     
  17. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    ZachariBarnes likes this.
  18. rLaister

    rLaister

    Joined:
    Jul 18, 2017
    Posts:
    2
    Also still happening in 2019.3.0f6 for me...
     
    ZachariBarnes likes this.
  19. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    I haven't seen this issue in years, but I also haven't used 2019.3.0f6. You guys should report a bug using [Help -> Report a Bug] in Unity.
     
  20. hromoyDron

    hromoyDron

    Joined:
    Jan 24, 2013
    Posts:
    90
    Still have this bug :(
    2019.2.21
     
  21. EdwinMurari

    EdwinMurari

    Joined:
    Jan 15, 2019
    Posts:
    6
    I just encountered it too.
     
  22. bgrz

    bgrz

    Joined:
    Mar 22, 2015
    Posts:
    59
    Same, 2019.2.21f1
     
  23. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
  24. nicolasgramlich

    nicolasgramlich

    Joined:
    Sep 21, 2017
    Posts:
    231
    Definitely still happening in
    2019.3.7.f1
    and it's unbelievable frustrating.... :mad:
     
  25. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    Seems like a recurring issue. It was solved in 5.4, then appeared, then solved again, now re-appeared. Downgrading to 2019.3.5, if possible, is one solution.
    I think it's a circular problem: they try to solve bug A by introducing bug B, then another team solves bug B re-introducing bug A.

    Of course, this is just speculation. But if true, this would require a higher level analysis of the causes before attempting to fix it again.

    @Tim-C , sorry to bother, I'm not sure if you're in charge with these things, but do you know if the team is aware that this bug recurs, or know where we can report this (other than the bug report tool)?
     
  26. Deeje

    Deeje

    Joined:
    Feb 1, 2014
    Posts:
    4
    Still happening in 2020.1.9, for what it's worth. Pretty frustrating.
     
  27. OlleStarclassic

    OlleStarclassic

    Joined:
    Apr 15, 2021
    Posts:
    1
    Still happening in 2020.3.4f1
     
  28. firfur

    firfur

    Joined:
    Nov 9, 2020
    Posts:
    5
    Still happeninh 2021.2.11f :)
     
  29. Cicaeda

    Cicaeda

    Joined:
    Sep 29, 2017
    Posts:
    34
    This is a separate issue from prefab hierarchy problems, but:

    Spawning even a single GameObject during [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] can cause your entire scene hierarchy to become a jumbled mess when you enter Play Mode in the editor. Using RuntimeInitializeLoadType.AfterSceneLoad instead seems to prevent this issue.

    I was spawning GameObjects in BeforeSceneLoad perfectly fine throughout Unity 2019, 2020LTS, and most of 2021LTS, until today when all of a sudden my scene hierarchy started scrambling every time I entered play mode. It happened even in newly created scenes. Reinstalling/upgrading Unity did not fix it. Deleting the library and all the cached files did not fix it either. I had to just turn off random stuff until I found what caused it.
     
    Gaban_ likes this.
  30. Gaban_

    Gaban_

    Joined:
    Feb 26, 2019
    Posts:
    2
    I have exact same problem as Cicaeda, the scene get messed up when i instantiate something with
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] attribute
    This is still not fixed in 2021.3.11f1 and it doesn't happen in my 2020.3.30f1 project