Editor vs EditorWindow: when do I use them?

I’ve been mucking about with creating editor scripts for use in future projects, but I’m always hit a brick wall when deciding which object to make. From what I’ve read, Editor scripts are attached to game objects, generally ScriptableObjects, to serialize data and are seen within the Inspector. Meanwhile, EditorWindows are not attached to game objects and appear within the toolbar near the top of the screen. However, the only things I really know about the two methods are their appearances and locations on the screen.

Do any other differences exist for Editor objects and EditorWindows? When should I reuse one over another? From my experience with coding Editor scripts, it seems more efficient to make EditorWindows, as they’re not attached to a game object which may not be included in a level I need it in due to some fault of my own.

To give any context, I’m making an Editor script which will allow users to control where and when a group of enemies will be spawned into the world. For now, I’m tinkering around with displaying the group within a circle on the ground and displaying their positions using Unity primitives. I’ll be using this script throughout the duration of the project, so it needs to be flexible for things like bosses, spawn patterns, and the like.

Should I use an Editor object or an EditorWindow for this solution?

1 Like

Editor;

  • Use to display a selectable item in the way you want in the Inspector. Most of the time, Unity’s own Inspector can do the job just fine. Used when you want to add something to it. Can also be replaced by a Property Drawer in some cases.

EditorWindow;

  • A new window. Usually invoked from a Menu using MenuItem attribute. Useful to handle multiple files, complex structure of data or to display stuff that is not related to a single item and where the Inspector is not useful.

In your case, since it involves OnSceneGUI and a GameObject, that would be an Editor.

And if you want your stuff to show up even if the GameObject is not selected, you have the OnDrawGizmos method you can add on your MonoBehaviour.

2 Likes