How to make a dynamic GUI ?

Hello there !

I’m having some troubles making an ingame interface with Unity GUI. Basically, I want to create a small interface to manage a database. Database isn’t the problem actually, the problem is Unity GUI itself.

If I have understood the Unity GUI system well, OnGUI() is called twice in a frame : the first time for layouting, the second time for paiting. Sometimes in my script, I refresh the DB view in my GUI which means that the GUI will change. It causes that error : “GUILayout: Mismatched LayoutGroup.Repaint”, which seems to be obviously related to the above-mentioned problem.

My question is simple : How can I avoid that problem ? Are there Unity GUI properties that would enable me to know which state the GUI system is currently in ?

Thanks in advance for your answer :slight_smile:

You can check Event.current.type to see what the EventType is.

change state only at end of frame using coroutines or in layout event. check event in OnGUI in Event.current.type