Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Any way to prevent Hierarchy window from collapsing when entering Play mode?

Discussion in 'Editor & General Support' started by dgoyette, Feb 13, 2019.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,203
    I pop in and out of play mode a lot, and every time I either enter or exit play mode, the Hierarchy view collapses. This gets pretty tedious if I'm working on a specific object nested within the hierarchy.

    Is there any way to prevent this behavior from happening? I'd prefer the hierarchy view's state not change when toggling Play mode.
     
    gohst and MaceB like this.
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,203
    It looks like this doesn't happen if I start a new project, leading me to believe there's something specific in my project that's causing this. Does anyone have any idea what type of code could be running to cause the root node in the Hierarchy view to collapse on Play mode change?
     
  3. Baydogan

    Baydogan

    Joined:
    Mar 22, 2018
    Posts:
    54
    I am having the same problem and I think I found the reason. I am using a PreloadScene and whenever I hit play, Scene changes to PreloadScene and then the Preload scene redirects me to the Original scene I am working on. Because of these two redirects, Original scene forgets about the hierarchy tree state. Now I am searching for a way to eliminate preload scene altogether or restoring tree state after redirect. If I find a way I will let you know. Hope this helps. Have a nice day :)
     
    Burlyduck likes this.
  4. Baydogan

    Baydogan

    Joined:
    Mar 22, 2018
    Posts:
    54
    BTW as a workaround until I find a definitive solution I am using this one-liner to select the game-object that I am working on in the hierarchy window.

    Code (CSharp):
    1. #if UNITY_EDITOR
    2.          UnityEditor.EditorGUIUtility.PingObject (gameObject);
    3. #endif
    Just paste this code to the script of the gameobject that you want to highlight in the hierarchy window.
     
    Czomperx3, korinVR, gotiobg and 7 others like this.
  5. Deleted User

    Deleted User

    Guest

    This is definitely a bug; it might be difficult to reproduce though. :(
     
  6. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,203
    I'm assuming it's some combination of packages and 3rd party code, which will be a bit annoying/time-consuming to tease apart and isolate. I'm pretty sure this doesn't happen on a brand new project. I'll just need to set aside an hour to fuss with things to see what combination of code causes this to happen.
     
  7. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,203
    Well, I spent the expected hour trying to triangulate what's causing the problem. Ultimately, I found the specific cause, but I don't yet understand the reason.

    My approach was to start deleting stuff from my project until the "collapse on play mode" behavior stopped happening. What I found is that it came down to a single Scene file in my project. If this Scene exists in my project, the bad collapse-on-play happens every time. If I remove the scene from the project, this behavior stops happening. Note that the presence of this scene in my project causes this behavior to happen in every other scene. So, it's not like this one scene collapses. Just having this one scene in the project causes this to happen in every scene.

    I deleted everything from the scene, and the problem persists. Interestingly, I also created a copy of the scene and deleted the original, and now the collapse-on-play behavior no longer happens.

    So, my only conclusion is that there's something just wrong with this scene, which isn't related to its content. In my case, I can simply create a copy of this scene, delete the original, and now the problem no longer occurs. However, dropping this scene into a new project does not cause the problem to occur (even if I import identical package). However, if I duplicate the entire project, the problem does occur. But I can't reproduce this in a small project. If I delete literally everything else in the project except for this scene, the problem no longer occurs. So, I'm left assuming there's some subtle interaction between this scene and something else in my project which causes this behavior to occur.

    Anyway, maybe if others are experiencing this issue they can try deleting individual scenes to see if it's something related to scenes. (Obviously make a backup first before butchering your project.) Or maybe it could be any possible file in the project, and in my case it was just a scene. For now, I guess I'm all set, but I'm sorry I can't contribute a reliable reproduction case to help isolate the issue.
     
  8. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,203
    More details on this. The behavior in my last post turned out to be just a side-effect. I claimed that it seemed to be caused by a certain scene, and I now believe that's completely wrong. I now believe this is actually caused by the "Addressables" package.

    I'm curious if any of the others who are running into this issue are also using Addressables in their project?

    Anyway, if I completely remove the Addressables from my project, this no longer occurs. The reason I thought it was related to a specific scene is actually due to an Addressables bug (https://forum.unity.com/threads/del...eference-when-building-player-content.700703/). What was happening is, I deleted the scene I thought was causing the problem. Then when entering play mode, addressables would throw an exception due to the bug described in that link, which I believe prevented Addressables from running the rest of the code it would normally run when starting up a scene. I believe that somewhere in that "rest of the code" the Addressables package is causing the hierarchy to be collapsed.

    Anyway, I guess now I'll look through the Addressables code to see if I can pinpoint why. It would be nice to know if others are using Addressables, or whether there are just a lot of different reasons this collapse-on-play behavior can occur.
     
    aka3eka likes this.
  9. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,203
    I found an easy way to reproduce this:
    • Import the addressables package.
    • Set the Play Mode Script to Virtual Mode.
    • Add at least one prefab to the Addressables list.
    • Now, either Build Player Content, or enter Play Mode, and the hierarchy view will collapse.
    I have a simple test case that reproduces this, which I'm trying to submit as a bug, if the bug report system starts responding...

    Anyway, it would be good to know if this is the same thing that's causing issues for others, or if there are many ways the collapse-on-play is triggered.

    I reported this as bug #1172252, and created a thread specifically to address it, just in case there are several causes for this collapse-on-play behavior: https://forum.unity.com/threads/bug...es-hierarchy-to-collapse-on-play-mode.716594/
     
    Last edited: Jul 26, 2019
    dogboydog and aka3eka like this.
  10. gohst

    gohst

    Joined:
    Jul 13, 2014
    Posts:
    5
    Time saver +.
     
  11. herbeste

    herbeste

    Joined:
    Feb 10, 2018
    Posts:
    1
    This is happening to me as well, Unity 2020.1.7f1.

    My project is literally a scene with a sprite with this script attached:

    void Update()
    {
    if (Input.GetButtonDown("Jump"))
    {

    SceneManager.LoadScene(0);
    }
    }

    and it collapses the hierarchy when I hit space. This is a ton of extra time in the process to not be able to have an object remain selected in the inspector.
     
    Mjeno likes this.
  12. sincerelysleepy

    sincerelysleepy

    Joined:
    Jan 15, 2019
    Posts:
    34
    I have this issue whenever a load scene occurs. It's getting extremely tedious. Do we have any feedback from the unity team about the issue? I'm using 2019.4.14f1
     
    AmazinJacks likes this.
  13. AmazinJacks

    AmazinJacks

    Joined:
    Oct 22, 2019
    Posts:
    9
    I'm having this problem as well. I'm reloading the scene using SceneManager for testing, but it collapses the whole hierarchy whenever it's called. Annoying.
     
    reinfeldx and sincerelysleepy like this.
  14. elfasito

    elfasito

    Joined:
    Jul 4, 2017
    Posts:
    51
    this happened to me too.
    as @dgoyette has said,
    I solved/workaround it changing "addressables play mode script" to: use Asset Database (fastest)
     
    Last edited: Mar 13, 2021
    burakkurkcu, Nefisto and dogboydog like this.
  15. sincerelysleepy

    sincerelysleepy

    Joined:
    Jan 15, 2019
    Posts:
    34
    This is still an issue. Any updates Unity folks?
     
    reinfeldx likes this.
  16. khrysller

    khrysller

    Joined:
    Mar 14, 2019
    Posts:
    125
    Still happening
     
    reinfeldx likes this.
  17. sincerelysleepy

    sincerelysleepy

    Joined:
    Jan 15, 2019
    Posts:
    34
    Yooo, can we get a fix or a bug report? It's extremely convenient having to re-expand your hierarchy everytime you hit play.
     
    mhctseu and reinfeldx like this.
  18. unity_05B59064C1E7A73BFCFC

    unity_05B59064C1E7A73BFCFC

    Joined:
    Sep 1, 2021
    Posts:
    5
    Still happening. In my case, the hierarchy started collapsing when I switched to play mode after I introduced
    DontDestroyOnLoad
    .
     
  19. RiseBasti

    RiseBasti

    Joined:
    Nov 4, 2018
    Posts:
    33
    The same here and I think that in my case it is also due to
    DontDestroyOnLoad
    .
     
  20. PixelFireXY

    PixelFireXY

    Joined:
    Nov 2, 2011
    Posts:
    56
    Still a problem
     
  21. File a bug report then.
     
  22. gotiobg

    gotiobg

    Joined:
    May 10, 2017
    Posts:
    19
    In combination with @Baydogan's answer I'm using this solution to select the game object I'm working on:

    Code (CSharp):
    1. #if UNITY_EDITOR
    2.         UnityEditor.EditorGUIUtility.PingObject(gameObject);
    3.         UnityEditor.Selection.activeGameObject = gameObject;
    4. #endif
    It selects the object in the hierarchy and also selects it in the inspector on the right for easy access to script values.
    You can paste this in the Start method of your script.
     
  23. burakkurkcu

    burakkurkcu

    Joined:
    Oct 2, 2016
    Posts:
    2
    This is still occurring in Unity 2023.1.11f1 on Intel based Mac, and it seems totally related with Addressables (v1.21.17) package for me as well.
    I was using in Addressables Group window under Play Mode Script as "Simulate Groups (advanced)".
    Then thanks to @elfasito, I switched it to over "Asset Database (fastest)" and it solved problem for me as well.
     
    luispedrofonseca likes this.
  24. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    947
    Thanks from the future! :)
     
  25. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,495
    There's a Like button on every post so you can express appreciation without dragging old dead threads up in everyone's feed.
     
  26. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    947
    Sorry for being appreciative!
    Ups... I did it again!