Query whether inspector is folded?

Hey, is there any way to query whether a custom editor (I call 'em inspectors) is collapsed/folded in the Unity editor via code?

I’m sure InternalEditorUtility.GetIsInspectorExpanded(target); is what you need. However Unity (or to be more precise the InspectorWindow) seperately tracks the visible state for each editor. The method i mentioned has to be passed the reference to the inspected object (editor.target).

If that doesn’t work it’s getting tricky since the InspectorWindow uses a seperate Tracker class to remember the visibility state on a per-index-base of the current editor array. With reflection almost everything is possible, but it quickly get very complex.


Well, i just wrote a little helper class that simplifies the access to the internal class InspectorWindow:

using UnityEditor;
using System.Runtime.InteropServices;

public static class InspectorWindowHelper
	private static System.Type m_InspectorWindowType = null;
	private static _MethodInfo m_GetAllInspectors = null;
	private static _MethodInfo m_GetTracker = null;
	static InspectorWindowHelper()
		foreach(var T in typeof(EditorApplication).Assembly.GetTypes())
			if (T.Name == "InspectorWindow")
				m_InspectorWindowType = T;
				m_GetAllInspectors = T.GetMethod("GetAllInspectorWindows",System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
				m_GetTracker = T.GetMethod("GetTracker",System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
	public static EditorWindow[] GetAllInspectorWindows()
		var array = m_GetAllInspectors.Invoke(null,null) as EditorWindow[];
		return array;
	public static ActiveEditorTracker GetTracker(EditorWindow aWin)
		var tracker = m_GetTracker.Invoke(aWin,null) as ActiveEditorTracker;
		return tracker;
	public static void EnforceExpanded(System.Type aCustomEditor)
		var windows = GetAllInspectorWindows();
		for(int n = 0; n < windows.Length; n++)
			var tracker = GetTracker(windows[n]);
			var editors = tracker.activeEditors;
			for(int i = 0; i < editors.Length; i++)
				if (editors*.GetType() == aCustomEditor)*
  •  		{*
  •  			int visible = tracker.GetVisible(i);*
  •  			if (visible == 0)*
  •  			{*
  •  				tracker.SetVisible(i,1);*
  •  			}*
  •  		}*
  •  	}*
  •  }*
  • }*
    I’ve added an example method (EnforceExpanded) to show what you can do with it and how to use it.
    EnforceExpanded can simply be called within OnInspectorGUI() of your custom inspector. Just pass the type of your editor class to prevent collapsing in all inspector windows.
    You didn’t say for what purpose you want that information and where you need it, so for the future you should be more precise when asking questions here.