How to Set a Hotkey for Unity's Lock Inspector Window

The Problem

Locking the Unity Inspector is essential for tasks like dragging multiple items into an array without losing focus. However, Unity provides no built-in keyboard shortcut for this action, and the command is not exposed in the Shortcuts Manager for easy, manual binding.

This guide details a simple way to create a Toggle Inspector Lock hotkey, which is reliable, portable, and does not require the creation of a profile to import.

The Solution: Create the Shortcut with a C# Script

This method is portable and will work in any Unity project that includes the script.

1. Create an Editor Folder: In your Unity project's Assets folder, create a new folder named Editor if one does not already exist. Editor scripts must be placed in a folder with this exact name.

2. Create a New C# Script: Inside the Editor folder, create a new C# script. You can name it LockInspectorShortcut.cs

3. Paste the Code: Open the script and replace its entire contents with the following code:

using UnityEditor;
using UnityEngine;
public class LockInspectorShortcut
{
[MenuItem("Tools/Toggle Inspector Lock %l")] // %l maps to Ctrl+L (Windows) or Cmd+L (macOS)
private static void ToggleInspectorLock()
{
// Get the currently active inspector window
var inspectorWindow = EditorWindow.GetWindow(
typeof(Editor).Assembly.GetType("UnityEditor.InspectorWindow")
);
// Check if we have a window
if (inspectorWindow == null)
{
Debug.LogWarning("Could not find Inspector window.");
return;
}
// Get the 'isLocked' property using reflection
var isLockedProperty = inspectorWindow
.GetType()
.GetProperty(
"isLocked",
System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public
);
if (isLockedProperty == null)
{
Debug.LogError("Could not find 'isLocked' property on Inspector window.");
return;
}
// Get the current lock state
bool isLocked = (bool)isLockedProperty.GetValue(inspectorWindow, null);
// Set the opposite lock state
isLockedProperty.SetValue(inspectorWindow, !isLocked, null);
// Repaint the window to show the updated lock icon
inspectorWindow.Repaint();
}
}

4. Save the File: Save the script. Unity will automatically compile it. The Ctrl+L (or Cmd+L on Mac) hotkey will now be active. You can test it by selecting an object, locking the Inspector with your new hotkey, and selecting a different object. The Inspector should remain focused on the original object.