Create EditorWindow from Editor.OnInspectorGUI

I’ve created a custom EditorWindow that currently does nothing, should just show an empty window.

public class MyEditorWindow : EditorWindow
{
...

  [MenuItem("Window/Animation Editor")]
  public static void EditAnimation()
  {
    MyEditorWindow window = new MyEditorWindow();
    window.Show();
  }

  protected void OnGUI()
  {
    // Doing nothing
  }
...
}

If I activate the window via the menu item, empty window spawns and all is well. If I call MyEditorWindow.EditAnimation() from a button click generated in OnInspectorGUI(), Unity hangs briefly before crashing out.

The editor log doesn’t show anything useful. I am running version 2.5.1f5 on Windows 7.

This is a simplified example of what I’m after, but should demonstrate the problem. While I can use a menu item to launch the animation editor, and then save the changes into the appropriate scene object from that window, it just doesn’t feel right. What I really want to do is inspect an object, edit its basic properties, and click a button to view the designer for the advanced properties on that specific object.

OK, I worked this out, however it’s using an undocumented function.

If you call EditorUtility.ExitGUI() immediately after you create/show the EditorWindow, everything works fine. One thing to note, you must not call any further GUILayout functions (including closing your existing sections/areas etc).