- Home /
How do I prevent an error when opening a scene from an EditorWindow?
I have a custom EditorWindow which when I click on of its buttons opens a new scene. However, when I do this I get the following error although the scene opens perfectly well.
NullReferenceException: Object reference not set to an instance of an object UnityEngine.GUILayoutUtility.EndLayoutGroup () (at C:/BuildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/Editor/GUILayoutUtility.cs:167) UnityEngine.GUILayout.EndVertical () (at C:/BuildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/Editor/GUILayout.cs:199) UnityEditor.HostView.OnGUI () (at C:/BuildAgent/work/14194e8ce88cdf47/Editor/Mono/GUI/DockArea.cs:126)
Any ideas?
Can you post the GUI code? Null refs can be a beast to debug without it.
I had a similar error, but I didn't have enough time to search for a working solution. You might try to do the Scene loading not in the "OnGUI" function, but in the Update function. Just set up a bool flag or string containing the scene name to load and check that in the Update function. Just a random idea... but maybe it works. ;)
I have this same issue. If you look at the above stack trace, you see "C:/BuildAgent..." For me, this error occurs at build-time and double-clicking the error does not take me to any code, nor are any of my scripts in the stack-trace. In fact, every script in the stack trace is in UnityEngine.dll or UnityEditor.dll. So this is obviously a Unity problem.
Yeah, I'm just ignoring it for now, it doesn't seem to be affecting anything..