- Home /
OnGUI updates several times a frame. Why?
Hi.
I noticed a few days ago that the OnGUI fuction updates way more than 1 time per frame. As a build in feature, why does it act that way? Like, would a update once a frame not be enough?
Answer by DaveA · Aug 24, 2011 at 07:39 PM
As it says here: http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnGUI.html
see here:
http://unity3d.com/support/documentation/ScriptReference/Event.html
which leads here:
http://unity3d.com/support/documentation/ScriptReference/EventType.html
Basically, it may go through several phases (event type) for doing layout, input, render, etc.
Is there a way to use OnGUI just for drawing, such as DEBUG GUI which I use it for, and have it do it once per frame?
Answer by Eric5h5 · Aug 24, 2011 at 07:42 PM
It depends on your code, but it has to do it at least twice because of getting the positions for things and then doing the actual layout. It's not arbitrarily running the code more than once.