Opening an EditorWindow from within another EditorWindow

Is there a way to open a separate editor window by pressing a button in another editor window?

For instance, I have an editor window for tracking people. I want to add a new person to the list, and click an “add New Person” button to do so. That button opens a separate editor window with fields for things like name and age.

I’ve managed to create that separate window with a class that extends editorwindow which I use a constructor to make a new instance of, but that always throws a warning about needing to use ScriptableObject.CreateInstance<> instead. I’ve tried that, along with a number of other things, but can’t seem to get the window to show at all.

Does anyone have any guidance on how to accomplish this?

There are basically two ways how to create and open and EditorWindow.

The first way is the one that’s usually mentioned in the docs: GetWindow<Type>()

GetWindow does several things at once:

  • It tries to find an already existing instance of that Type
  • If no existing instance was found, it creates one
  • Finally it also shows the window.

The second way is the “manual” way using ScriptableObject.CreateInstance

// create a new instance
YourEditorWindow inst = ScriptableObject.CreateInstance<YourEditorWindow>();

// show the window
inst.Show();

Note: the main difference between GetWindow and CreateInstance is that GetWindow will never open a second window of the same type. It will always reuse an existing one it one is found. With CreateInstance you can create as many instances of the same type as you want. Just keep in mind you have to call one of the Show method in order to make it visible.