Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Unity Editor keyboard shortcut to close active undocked window
using UnityEngine;
using UnityEditor;
using System.Reflection;
public static class CloseActiveWindow
[MenuItem("Edit/Close Active Window ^w", false, -101)]
public static void CloseWindow()
var window = EditorWindow.focusedWindow;
if (window != null)
// check if window is undocked:
BindingFlags fullBinding = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;
MethodInfo isDockedMethod = typeof(EditorWindow).GetProperty("docked", fullBinding).GetGetMethod(true);
if ((bool)isDockedMethod.Invoke(window, null) == false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment