Search Unity

[Released] Session Restore

Discussion in 'Assets and Asset Store' started by AndrewRH, Jul 21, 2017.

  1. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    Cover-1950x1300.png
    Session Restore
    Latest version: 2.0.1 released 28 June 2022

    Hi Everyone,

    We've just released a must-have productivity Unity extension called Session Restore. This is an editor extension for anyone working on multiple Unity scenes/projects and knows how distracting context switching is and wants to improve the workflow of their team.

    AssetStoreImage3.png
    The first feature is that it restores your Hierarchy window state in Unity. This means when you start Unity or switch between scenes, it will set the Hierarchy window to the state when you worked on it last (same GameObjects expanded, same GameObjects selected).


    Without this script Unity always opens up the Hierarchy view collapsed and with nothing selected, which personally I find annoying :) It also resets the Hierarchy when you make a build or play the scene which compounds the issue.

    This script also restores the scene view and prefab windows so you can continue where you left off when switching between multiple Unity projects.

    Features:
    • Restores hierarchy window
    • Restores selection state
    • Restores scene view camera
    • Improves workflow and sanity
    • No setup, just import the package and it starts working immediately
    • Highly optimised, you won't even know it's there
    • Unity 5.6 - 2022.x supported
    • All Unity platforms supported
    • Full source code included

    You can find it here on the Unity Asset Store.

    Thanks,
     
    Last edited: Jun 28, 2022
    AGregori and neoshaman like this.
  2. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    Please post reviews on the Asset Store if you do try it out :)
     
  3. MrIconic

    MrIconic

    Joined:
    Apr 5, 2013
    Posts:
    239
    I thought about this the other day. Then this appeared.

    Haven't tried it yet but I appreciate the creation.
     
    AndrewRH likes this.
  4. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    *BUMP* Please comment here or post reviews on the Asset Store if you do try it out :)
     
  5. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    Any feedback? Anyone tried it? :)
     
  6. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    Hi Everyone,

    Version 1.3 has just been released. Changes are:
    • Fixed issue where “Maximise on Play” would spawn another Hierarchy window
    • Fixed Unity 5.0.x script compile errors
    • Improved detection method for Hierarchy window
    Drop us a review/message if you like this script :)

    Thanks,
     
  7. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    Hi Everyone,

    Version 1.4 has just been released. Changes are:
    • Added support for Unity 2018.3.x as it changed some internal classes
    • Added support for expanding collapsed scenes
    • Improved detection of changed hierarchy window
    • Refactored reflection caching code
    • Fixed a deprecated method warning for hierarchyChanged
    Drop us a review/message if you like this script :)

    Thanks,
     
    Lars-Steenhoff likes this.
  8. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    I like it!
     
  9. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    I have one request, when I press play it also loses my selected hierarchy object ,can you also make it to keep this selected ?

    Mac with 2018.3.0f2


    Edit: Its working after a restart of unity
     
  10. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    Thanks for the feedback ;)
    Yes, there are a few edge cases where it doesn't save the selection immediately...it should be fine in 95% of cases though. Thanks,
     
    Lars-Steenhoff likes this.
  11. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    Hi Everyone,

    Version 1.4.1 has just been released. Changes are:
    • Added support for the new Prefab Mode editor in 2018.3.x, so that the plugin doesn’t operate while the hierarchy window is in this mode
    Drop us a review/message if you like this script :)

    Thanks,
     
    Lars-Steenhoff likes this.
  12. UnityEJC

    UnityEJC

    Joined:
    Sep 3, 2019
    Posts:
    1
    This is just what I need, but I can't seem to get it to work. I downloaded and imported it into my project. It shows in the Project window, but not in the Hierarchy window. If I build, or if I close Unity and reopen it, my hierarchy gets collapsed. The manual says it's supposed to automatically work. Did I miss a step? (I'm fairly newbie.) I'm using 2019.2.4f1. Thank you.
     
  13. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    Yeah it probably doesn't yet support some of these newer Unity versions.....
     
  14. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    Would you have time to make it work with 2019.4 ?

    Thanks
     
  15. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    Yeah...it's on my mental list of things to do :) Just no time right now.....Hopefully soon!
     
    Lars-Steenhoff likes this.
  16. NathanRH

    NathanRH

    Joined:
    Oct 24, 2012
    Posts:
    447
    Hi Everyone,

    Hierarchy Restore version 1.5.0 has just been released!

    You can find the updated version on the Asset Store
    Changes in this version include:
    • Added support for Unity 2019 and 2020
    • Added new feature to restore the scene view window
    • Better detection of changes in hierarchy collapsed state
    • Added options to Unity’s Preferences window
    • Minimum supported version is now Unity 5.6
    Thanks to everyone that reported bugs that were fixed in this release :)
     
    Lars-Steenhoff likes this.
  17. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    Thanks for the update! really welcome
     
  18. Andresmonte

    Andresmonte

    Joined:
    Nov 22, 2014
    Posts:
    37
    hello, I made some changes (fixes for me) that you could implement in a more elegant way.

    Code (CSharp):
    1. #if UNITY_5_3 || UNITY_5_4_OR_NEWER
    2. #define RH_UNITY_FEATURE_SCENEMANAGMENT2
    3. #endif
    4. using UnityEngine;
    5.  
    6. #if UNITY_EDITOR
    7. using UnityEditor;
    8.  
    9. //-----------------------------------------------------------------------------
    10. // Copyright 2017-2020 RenderHeads Ltd.  All rights reserved.
    11. //-----------------------------------------------------------------------------
    12.  
    13. namespace RenderHeads.Framework.Editor
    14. {
    15.     public partial class HierarchyNode : MonoBehaviour
    16.     {
    17.         static bool wasPayingFlag;//ugly but works
    18.         private void Start()
    19.         {
    20.             ///second change
    21.             if(wasPayingFlag)//if i was playing the game in the editor
    22.             {
    23.                 wasPayingFlag = false;//reset the flag
    24.                 return;//The reason: I want the same behavior of unity when playing and then stoping.
    25.                        //so instead of restoring the selection and hierarchy, when exiting play mode.
    26.                        //I just use the default behavior.
    27.             }
    28.             ///
    29.  
    30.             if(!HierarchyRestore.IsEnabled) return;
    31.             RestoreSelection();
    32.         }
    33.         private void UpdateSceneGUID()
    34.         {
    35. #if RH_UNITY_FEATURE_SCENEMANAGMENT2
    36.             ///dint work for me
    37.             ///the whole hierarchy is being reset, every time I hit play
    38.             //_sceneGUID = GetSceneGUID(EditorSceneManager.GetActiveScene().path);
    39.  
    40.             ///first change
    41.             _sceneGUID = gameObject.scene.path;//I have a script that dynamically changes the active scene, every time I hit play or stop.
    42.                                                //so I prefer to get the scene from the object rather than the scene manager                                            
    43.             ///
    44.  
    45. #else
    46.             _sceneGUID = GetSceneGUID(EditorApplication.currentScene);
    47. #endif
    48.         }
    49.  
    50.         private void Update()//added just to set the flag
    51.         {
    52.             if(Application.isPlaying)
    53.                 wasPayingFlag = true;
    54.         }
    55.     }
    56. }
    57. #endif
    Thank you for this asset, for me, unity crashes all the time, so this is a time/sanity saviour.
     
    Last edited: Mar 1, 2021
    NathanRH likes this.
  19. NathanRH

    NathanRH

    Joined:
    Oct 24, 2012
    Posts:
    447
    Thanks tavovallejo for these changes! We will take a look and see whether we can get them into the next update.
     
    Andresmonte likes this.
  20. Andresmonte

    Andresmonte

    Joined:
    Nov 22, 2014
    Posts:
    37
    So i made anther change, I set the Script Execution Order of HierarchyNode to -15000, to get rid of "[HierarchyRestore] Can't find node with path:" . Warnings are logged if you changed the name of the objects.
     
    NathanRH likes this.
  21. Rabadash8820

    Rabadash8820

    Joined:
    Aug 20, 2015
    Posts:
    94
    @NathanRH I just upgraded to Unity 2021.2 and got compile errors in
    Scripts/HierarchyUitls.cs
    . Looks like
    IsHierarchyWindowInPrefabMode
    is using the
    UnityEditor.Experimental.SceneManagement.PrefabStageUtility
    API, but this API is no longer experimental in 2021.2 The correct type name is now
    UnityEditor.SceneManagement.PrefabStageUtility
    . I'm guessing you'll want another precompiler define for whether or not prefab edit mode is experimental.
     
  22. Rabadash8820

    Rabadash8820

    Joined:
    Aug 20, 2015
    Posts:
    94
    Also after updating to Unity 2021.2, I've noticed several warnings that say "SceneView rotation is fixed to identity when in 2D mode. This will be an error in future versions of Unity." It looks like the
    RenderHeads.Framework.Editor.SceneViewState.RestoreState
    method should be checking if the current scene is in 2D mode before restoring the scene view rotation. That is, there should be a
    SceneView.in2DMode
    check before the line
    sv.rotation = Load("SceneView.Rotation", sceneId, sv.rotation)
    .
     
  23. NathanRH

    NathanRH

    Joined:
    Oct 24, 2012
    Posts:
    447
    @Rabadash8820 thanks for reporting these issues. We have not tested on Unity 2021 yet. We will get these issues fixed and release a new version soon.

    Thanks,
     
  24. NathanRH

    NathanRH

    Joined:
    Oct 24, 2012
    Posts:
    447
    Thanks again for reporting these issues - we've uploaded a new build to the Asset Store with these issues fixed.
     
  25. Rabadash8820

    Rabadash8820

    Joined:
    Aug 20, 2015
    Posts:
    94
    Awesome, thanks for the quick turnaround!
     
    NathanRH likes this.
  26. ledshok

    ledshok

    Joined:
    Oct 28, 2012
    Posts:
    28
    This asset is a real time saver - thank you!

    Any chance that multiple scenes will be supported in the future? Even if it's just to restore all open scenes when Unity loads ie no need to remember the hierarchy state (open/closed) if that's the main challenge.

    Thanks! :)
     
    AndrewRH likes this.
  27. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    What do you mean restore all open scenes? If you could give more information then it's certainly something we can look into.

    If you have a moment we would really appreciate a short rating/review on the Asset Store :)

    Thanks,
     
  28. ledshok

    ledshok

    Joined:
    Oct 28, 2012
    Posts:
    28
    Ha, now that I try to reproduce the issue....I can't! :)

    In essence, I had a project with two scenes open (ie using Open Scene Additive) but whenever Unity started up only one of them would be loaded ie I'd need to find the other scene in the project folder and do Open Scene Additive again. So the issue wasn't really with restoring the expanded/collapsed/selected state of a scene, rather that one of the scenes wasn't being opened at all.

    Anyway, it doesn't seem to be happening any more, so that's good.

    And yes, more than happy to leave a review. It's a great asset!
     
    Last edited: Apr 2, 2022
    AndrewRH likes this.
  29. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    Thanks for the review!

    Strange that that can't be reproduced. Well let us know if you have any other suggestions/issues.
     
  30. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    Hi All, sorry about the cross-post, but I just wanted to announce a new RenderHeads plugin for Unity:
    External Game View

    It's a plugin for multi-monitor productivity and workflow improvement while using the Unity Editor and it's really changed the way we work. You can find out all about it here where you'll find documentation and a tutorial video.
    Thanks,
     
    Rabadash8820 likes this.
  31. Rabadash8820

    Rabadash8820

    Joined:
    Aug 20, 2015
    Posts:
    94
    I've been seeing an error from Hierarchy Restore every now and then. It's very infrequent so I've had trouble pinning down exactly what causes it, but I know I've seen it in an existing project when getting it set up on a new dev machine. Still, it looks like the most reliable repro step is just to import Hierarchy Restore into a fresh Unity project. Doing this, I get the following error:

    InvalidOperationException: Sequence contains no matching element
    System.Linq.Enumerable.Single[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] predicate) (at <1e18c5a6594041c9844bfd0b6618ee4a>:0)
    UnityEditor.SceneRenderModeWindow.GetBuiltinCameraMode (UnityEditor.DrawCameraMode drawMode) (at <a017e354f3154926a5617fbac3a64fcc>:0)
    UnityEditor.SceneView.GetBuiltinCameraMode (UnityEditor.DrawCameraMode mode) (at <a017e354f3154926a5617fbac3a64fcc>:0)
    RenderHeads.Framework.Editor.SceneViewState.RestoreState (System.String sceneId) (at Assets/Plugins/RenderHeads/HierarchyRestore/Scripts/SceneViewState.cs:20)
    RenderHeads.Framework.Editor.HierarchyNode.RestoreSceneViewState (System.String sceneId) (at Assets/Plugins/RenderHeads/HierarchyRestore/Scripts/HierarchyNode.cs:302)
    RenderHeads.Framework.Editor.HierarchyNode.RestoreSelection () (at Assets/Plugins/RenderHeads/HierarchyRestore/Scripts/HierarchyNode.cs:89)
    RenderHeads.Framework.Editor.HierarchyNode.Start () (at Assets/Plugins/RenderHeads/HierarchyRestore/Scripts/HierarchyNode.cs:38)​

    It looks like the offending line of
    SceneViewState.RestoreState
    is trying to get a
    CameraMode
    for a specific
    DrawCameraMode
    , where the latter is pulled from
    EditorPrefs
    . Presumably, if that
    EditorPrefs
    value is not present, then the
    DrawCameraMode
    is being set incorrectly, causing the
    SceneView.GetBuiltinCameraMode
    call to fail.

    Like I said, this error is super infrequent, but showing this error after a fresh install is kind of a bad look, so figured I should report. :p
     
    AndrewRH likes this.
  32. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
  33. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    Which version of Unity were you using?
     
  34. Rabadash8820

    Rabadash8820

    Joined:
    Aug 20, 2015
    Posts:
    94
    Ah, forgot to put that. My environment:
    • Unity: 2021.3.2f1
    • Unity platform: Android
    • OS: Windows 11 Pro
    • Hierarchy Restore: 1.5.1
     
  35. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    Thanks, I haven't been able to reproduce the issue. I've created a blank scene in 2021.3.2f1 and imported the package but no errors happen. I've tried this a few times. Any other suggestions to reproduce it?

    Also could you try editing SceneViewState.cs line 18-23 and changing it to this:

    Code (CSharp):
    1.                 try
    2.                 {
    3.                     #if UNITY_2018_2_OR_NEWER
    4.                     DrawCameraMode drawCameraMode = (DrawCameraMode)Load("SceneView.CameraMode", sceneId, (int)DrawCameraMode.Normal);
    5.                     sv.cameraMode = SceneView.GetBuiltinCameraMode(drawCameraMode);
    6.                     #else
    7.                     sv.renderMode = (DrawCameraMode)Load("SceneView.RenderMode", sceneId, (int)sv.renderMode);
    8.                     #endif
    9.                 }
    10.                 catch (System.InvalidOperationException)
    11.                 {
    12.                     // Silently catch this exception that has been reported in Unity 2021.3.2f1
    13.                     // Presumably because a DrawCameraMode enum index changed or became invalid.
    14.                 }
    Thanks,
     
  36. Rabadash8820

    Rabadash8820

    Joined:
    Aug 20, 2015
    Posts:
    94
    Hi @AndrewRH, sorry for taking so long to get back to you. Looks like my repro environment was incorrect; the error is actually occurring on MacOS (Monterey, version 12.3.1 on Intel silicon). The repro steps are otherwise the same. I'm unable to fix the issue just by modifying the script you recommended, as there's no way to modify the script before importing into Unity.
     
  37. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    We'll release a new version on the asset store tomorrow so you can try importing one with those changes.

    Thanks for your feedback,
     
    Rabadash8820 likes this.
  38. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    Today we are renaming this asset from Hierarchy Restore to Session Restore. The new name is more suitable as this asset does more now than just restoring the hierarchy window. A new version will be released later today with the new name and a new price.
     
    Rabadash8820 likes this.
  39. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    Hi @Rabadash8820,

    The new version is up on the store now. Hopefully that fixes the issue you were having with importing on macOS.

    Please note that the package has been renamed so you should delete the old asset before importing the new package.

    Thanks,
     
  40. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Hello @AndrewRH ,
    I just installed session restore and now when I enter play mode without any object selected, it automatically selects the last selected object in the hierarchy.
    It's very annoying because having a physics object selected while on play mode makes the physics engine all jerky, so I have to deselect it again once entering play mode and then click on the play view again to have input.
    Could you fix this?
     
  41. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    Thanks, that does sound annoying. We'll look into this and get back to you soon.
     
    atomicjoe likes this.
  42. Rabadash8820

    Rabadash8820

    Joined:
    Aug 20, 2015
    Posts:
    94
    Sweet, looks like v2.0.0 fixed that MacOS error when first installing the asset. Nice job!
     
    AndrewRH likes this.
  43. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    New version 2.0.1 is out with this change.

    Thanks,
     
  44. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    @atomicjoe

    Here's the new setting in 2.0.1:
    upload_2022-6-28_11-16-50.png

    Thanks,
     
    atomicjoe likes this.
  45. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Great! thanks a ton! :)
     
  46. Rabadash8820

    Rabadash8820

    Joined:
    Aug 20, 2015
    Posts:
    94
    I am getting the below error every time I enter Play Mode.

    Code (CSharp):
    1. GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced.
    2. UnityEditor.EditorWindow:SendEvent (UnityEngine.Event)
    3. RenderHeads.SessionRestore.HierarchyUtils:FocusHierarchyWindow (bool) (at Assets/Plugins/RenderHeads/SessionRestore/Scripts/HierarchyUtils.cs:244)
    4. RenderHeads.SessionRestore.HierarchyNode:RestoreState () (at Assets/Plugins/RenderHeads/SessionRestore/Scripts/HierarchyNode.cs:179)
    5. RenderHeads.SessionRestore.HierarchyNode:RestoreSelection () (at Assets/Plugins/RenderHeads/SessionRestore/Scripts/HierarchyNode.cs:196)
    6. RenderHeads.SessionRestore.HierarchyNode:Start () (at Assets/Plugins/RenderHeads/SessionRestore/Scripts/HierarchyNode.cs:76)
    I have tried restarting Unity, restarting my computer, and reimporting all assets, but it still continues. My environment:
    • Session Restore: 2.0.1
    • Unity: 2022.2.15f1
    • OS: Windows 11 Pro
    The statement throwing the error is
    hierarchyWindow.SendEvent(frameEvent);
    inside
    HierarchyUtils.FocusHierarchyWindow
    . It looks like this method is potentially called twice in the same frame in
    HierarchyNode.RestoreState
    , which would result in multiple
    SendEvent
    calls per frame. I have no idea if this is the root cause of the error, but maybe. ¯\_(ツ)_/¯

    Out of curiosity, is there a way to contribute to Session Restore's source code? I sometimes tweak the package code locally, but those changes always get overwritten by the next update and version control can't really help since the code files end up in the gitignored Library folder. I would love to be able to submit Pull Requests to the official codebase, but I don't see it in the list of RenderHeads GitHub repos.
     
  47. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    Can you add a setting to restore also the project view selected item? ( if that was the last in focus )
     
    atomicjoe likes this.
  48. Rabadash8820

    Rabadash8820

    Joined:
    Aug 20, 2015
    Posts:
    94
    FYI, Session Restore is showing a new warning in Unity 2023.2:

    > Assets\Plugins\RenderHeads\SessionRestore\Scripts\HierarchyNode.cs(102,11): warning CS0618: 'Object.FindObjectOfType<T>()' is obsolete: 'Object.FindObjectOfType has been deprecated. Use Object.FindFirstObjectByType instead or if finding any instance is acceptable the faster Object.FindAnyObjectByType'