EditorGUILayout.BeginVertical Rect returns both 0 and correct values in the same frame

Small quick question, is there a reliable way to get the rect from EditorGUILayout.BeginVertical and BeginHorizontal?

Everytime I try to get either of these, it returns both 0 and the actual value of the rect in the same frame causing it to always read 0 when used elsewhere.

private void OnGUI()
{
            inspectorRect = EditorGUILayout.BeginVertical("box", GUILayout.ExpandHeight(true));
            Debug.Log(inspectorRect);
}

It takes multiple frames for IMGUI to calculate layout.

You can check what stages its at with Event.current.type. EventType.Layout means its still calculating layout: Unity - Scripting API: EventType.Layout

2 Likes

Ah awesome, Cheers @spiney199

Ended up doing this:

private void OnGUI()
{
      var rect = EditorGUILayout.BeginVertical("box", GUILayout.ExpandHeight(true));

      if (Event.current.type != EventType.Layout)
      {
             inspectorRect = rect;
      }
}
1 Like