Skip to main content
  1. Blogs/

Unity: Getting GUILAyout: Mismatched LayoutGroup.repaint? Try EventType.Repaint

·259 words·2 mins·
unity code c#

I built a great custom Unity Editor window. It does all the things.

Except it’s buggy.

It’s a sort of window-based GUI. I have mini windows inside of a normal Unity custom Editor Window. At some point I implemented the ability to rearrange which window is on top.

Then the trouble started.

a bunch of errors

“GUILayout: Mismatched LayoutGroup.repaint”

I’ve been struggling on and off for days with this. The exception is thrown at odd places deep in my GUI code. But it turns out the problem is when I was reordering the stack of windows.

Each window tracks if it is currently selected. This is used to change the style of the window. What I decided to do is, at the end of the OnGUI loop, check if the window that is selected is at the end of the list of windows (since they are rendered from 0 on up). If the selected window is not at the end of the list, then move it.

This generally gets the windows to stack properly, but then I sometimes get these odd exceptions.

It turns out it has something to do with how Unity’s Editor GUI works. It performs multiple passes, and at certain passes it expects things to not change. Changing the order of the windows changes the order of EditorGUILayout calls, among other things.

The fix was to ensure that I change the window ordering when the current EventType is Repaint:

if(Event.current.type == EventType.Repaint) {
    if(selectedNode > -1 && selectedNode < nodes.Count - 1) {
      // Change window order here
    }
}

Related

Yes, you CAN serialize abstract classes in Unity
·1206 words·6 mins
unity code c#
A single method that can work with either a List or an Array (IEnumerable and ICollection)
·296 words·2 mins
unity code tips c#
Testing C# code in the browser
·42 words·1 min
code tips c#
Element-wise Vector Multiplication in Unity (Vector3.Scale)
·79 words·1 min
unity code tips
The top 5 things Ive learned as an Indie Unity Developer
·1402 words·7 mins
unity programming code tips
Round a number to some multiple of another number
·201 words·1 min
code tips