Getting control ID to match with GUIUtility.hotControl

How do I determine the ID of the last drawn GUI control? I’d like to be able to do something along these lines:

myObject.expanded = EditorGUILayout.Foldout(myObject.expanded, myObject.label);
int id = ???get control ID???;

if (GUI.hotControl == id) {
  // do something 
}

For example, I might want to render the foldout’s ‘child’ elements differently if the foldout is ‘hot’.

Is there such a function? Or, perhaps, a way to specify the ID for the next control, as GUI.SetNextControlName() does for the string identifier?

1 Like

see this:

Ugly and nasty use of side effects but its the only soln I’ve found that works.