I have a simple editor script that I want to run from an EditorWindow but am running into a minor problem:
I have an OnGUI function that displays a string and two buttons. When you click the first button it will run a function and then close the window. When you click the second button it will just close the window.
Everything functions normally but after the first button runs it’s function and closes I get an “ArgumentException: You can only call GUI functions from inside OnGUI”. However the line it brings me to is inside an OnGUI call. Is there something I’m missing? Here is the OnGUI function that runs from my class that inherits from EditorWindow.
void OnGUI()
{
GUILayout.Label("Save current scene in order to continue!", EditorStyles.boldLabel);
if(GUILayout.Button("Yes"))
{
bool shouldContinue = EditorApplication.SaveScene(EditorApplication.currentScene);
if(shouldContinue)
{
Foo();
this.Close();
}
}
if(GUILayout.Button("No")) //this is where the console error brings me if I hit the Yes button
{
this.Close();
}
}