Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


EditorWindow

Derive from this class to create a custom Editor window.
Read time 8 minutesLast updated 5 days ago

Definition

[ExcludeFromObjectFactory]public class EditorWindow : ScriptableObject

Remarks

Use this class to create Editor windows that can either float independently or dock as tabs, similar to the default windows in the Unity Editor.
You can use the MenuItem attribute to configure an Editor window to be opened in the Unity Editor menu.
When creating a custom Editor window, follow these guidelines:
  • Put code dependent on UXML/USS loading in the CreateGUI method to ensure that all necessary assets are available.
  • Keep the event registration code inside CreateGUI or after CreateGUI is called.
The following diagram shows the order of execution of an Editor window:
UIE order of editor window (EditorWindow)
  • OnEnable: Called when the script is loaded or when the object is enabled.
  • EditorApplication.isUpdating: If true, the Editor is currently refreshing the AssetDatabase.
  • CreateGUI: Generates the graphical user interface if the Editor is not updating.
  • Update: Called multiple times per second on all visible windows.
  • OnGUI: Called multiple times per frame for rendering and handling GUI events.
  • OnDisable: Called when the script is disabled or the object is destroyed to finalize and clean up resources.
For an example on how to create an Editor window that reacts to user input, refer to Create a custom Editor window with C# script.

Examples

using UnityEditor;using UnityEngine;using UnityEngine.UIElements;public class MyEditorWindow : EditorWindow{ [MenuItem("Examples/My Editor Window")] public static void ShowExample() { MyEditorWindow wnd = GetWindow<MyEditorWindow>(); wnd.titleContent = new GUIContent("MyEditorWindow"); } public void CreateGUI() { // Each editor window contains a root VisualElement object VisualElement root = rootVisualElement; // VisualElements objects can contain other VisualElement following a tree hierarchy Label label = new Label("Hello World!"); root.Add(label); // Create button Button button = new Button(); button.name = "button"; button.text = "Button"; root.Add(button); // Create toggle Toggle toggle = new Toggle(); toggle.name = "toggle"; toggle.label = "Toggle"; root.Add(toggle); }}

Properties

Property

Description

autoRepaintOnSceneChangeEnable this property to automatically repaint the window when the SceneView is modified.
dataModeControllerAn instance of IDataModeController to handle DataMode functionalities for the current window.
dockedReturns true if EditorWindow is docked.
hasFocusReturns true if EditorWindow is focused.
hasUnsavedChangesThis property specifies whether the Editor prompts the user to save or discard unsaved changes before the window closes.
maximizedWhether or not this window is maximized?
maxSizeThe maximum size of this window when it is floating or modal. The maximum size is not used when the window is docked.
minSizeThe minimum size of this window when it is floating or modal. The minimum size is not used when the window is docked.
overlayCanvasThe OverlayCanvas for this window.
positionThe desired position of the window in screen space.
rootVisualElementRetrieves the root visual element of this window hierarchy.
saveChangesMessageThe message that displays to the user if they are prompted to save
titleContentThe GUIContent used for drawing the title of EditorWindows.
wantsLessLayoutEventsSpecifies whether a layout pass is performed before all user events (for example, EventType.MouseDown or EventType.KeyDown), or is only performed before repaint events.
wantsMouseEnterLeaveWindowChecks whether MouseEnterWindow and MouseLeaveWindow events are received in the GUI in this Editor window.
wantsMouseMoveChecks whether MouseMove events are received in the GUI in this Editor window.

Static Properties

Property

Description

focusedWindowThe EditorWindow which currently has keyboard focus. (Read Only)
mouseOverWindowThe EditorWindow currently under the mouse cursor. (Read Only)

Methods

Method

Description

AwakeCalled as the new window is opened.
BeginWindowsMark the beginning area of all popup windows.
CloseClose the editor window.
CreateGUICreateGUI is called when the EditorWindow's rootVisualElement is ready to be populated.
DiscardChangesDiscards unsaved changes to the contents of the window.
EndWindowsClose a window group started with EditorWindow.BeginWindows().
FocusMoves keyboard focus to another EditorWindow.
GetExtraPaneTypesGets the extra types of EditorWindow associated with the current window.
OnBackingScaleFactorChangedCalled when the UI scaling for this EditorWindow is changed.
OnBecameInvisibleCalled after the window is removed from a container view, or is no longer visible within a tabbed collection of EditorWindow.
OnBecameVisibleCalled after the window is added to a container view.
OnDestroyOnDestroy is called to close the EditorWindow window.
OnFocusCalled when the window gets keyboard focus.
OnGUIImplement your own editor GUI here.
OnHierarchyChangeHandler for message that is sent when an object or group of objects in the hierarchy changes.
OnInspectorUpdateOnInspectorUpdate is called at 10 frames per second to give the inspector a chance to update.
OnLostFocusCalled when the window loses keyboard focus.
OnProjectChangeHandler for message that is sent whenever the state of the project changes.
OnSelectionChangeCalled whenever the selection has changed.
RemoveNotificationStop showing notification message.
RepaintMake the window repaint. This queues a command to render the window on the next frame.
SaveChangesPerforms a save action on the contents of the window.
SendEventSends an Event to a window.
ShowShow the EditorWindow window.
ShowAsDropDownShows a window with dropdown behaviour and styling.
ShowAuxWindowShow the editor window in the auxiliary window.
ShowModalShow modal editor window.
ShowModalUtilityShows the EditorWindow as a floating modal window.
ShowNotificationShow a notification message.
ShowPopupShows an Editor window using popup-style framing.
ShowTabShows a docked Editor window.
ShowUtilityShow the EditorWindow as a floating utility window.
TryGetOverlayGet an Overlay with matching ID from an EditorWindow canvas.
UpdateCalled multiple times per second on all visible windows.

Static Methods

Method

Description

CreateWindowCreates an EditorWindow of type
T
.
FocusWindowIfItsOpenFocuses the first found EditorWindow of specified type if it is open.
GetWindowReturns the first EditorWindow of type
windowType
which is currently on the screen.
GetWindowWithRectReturns the first EditorWindow of type
t
which is currently on the screen.
HasOpenInstancesChecks if an editor window is open.

Static Events

Member

Description

windowFocusChangedCalled whenever the focused editor window is changed.

Inheritance

Inherited Members

Operators

Operator

Description

operator ==Compares two object references to see if they refer to the same object.
boolDetermines whether the object exists.
operator !=Compares if two objects refer to a different object.