Null reference when dynamically loading a scene

Issue #221 wontfix
Anonymous created an issue

I created an object inheriting SerializedMonoBehaviour, and a button on it loads another scene and closes the current one, When the button is hit and the new scene is loaded, the following exceptions are raised:

NullReferenceException: SerializedObject has been Disposed Sirenix.OdinInspector.Editor.InspectorUtilities.EndDrawPropertyTree (Sirenix.OdinInspector.Editor.PropertyTree tree) (at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Infos/InspectorPropertyInfo.cs:507) Sirenix.OdinInspector.Editor.PropertyTree.Draw (Boolean applyUndo) (at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Utilities/Persistent/PersistentContextCache.cs:183) Sirenix.OdinInspector.Editor.OdinEditor.OnInspectorGUI () (at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Misc/DrawerPriority.cs:380) UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor[] editors, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1240) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Do I do something wrong?

Comments (4)

  1. Florent Falcy

    Hello, I'm have same problem on a ScriptableObject.

    Description :

    1. Create a ScriptableObject Class with a inspector Button that call EditorSceneManager.NewScene
    2. Instanciate this ScriptableObject
    3. Select created asset and clic on button

    Result :

    2 errors - see this attached Unity project for reproduction and fullstack error.

    NullReferenceException: SerializedObject has been Disposed Sirenix.OdinInspector.Editor.InspectorUtilities.EndDrawPropertyTree (Sirenix.OdinInspector.Editor.PropertyTree tree) (at C:/Sirenix/Sirenix

    InvalidOperationException: Operation is not valid due to the current state of the object System.Collections.Stack.Pop () (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections/Stack.cs:329)

  2. Tor Esa Vestergaard

    Upon looking closer at this issue, it's not something we can really fix. Part of the problem is Unity itself breaking in a way we can't really do anything about.

    Essentially, what you should be doing instead is changing the scene in a delayed callback, and not from the middle of the GUI drawing process:

    EditorApplication.delayCall += () =>
    {
        EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
        Selection.activeObject = this;
    };
    
  3. Log in to comment