why would Unity call OnGUI twice pwe frame?
function Update() {
print("Update " + Time.frameCount);
}
function LateUpdate() {
print("LateUpdate " + Time.frameCount);
}
function OnGUI () {
print("OnGUI " + Time.frameCount);
}
why would Unity call OnGUI twice pwe frame?
function Update() {
print("Update " + Time.frameCount);
}
function LateUpdate() {
print("LateUpdate " + Time.frameCount);
}
function OnGUI () {
print("OnGUI " + Time.frameCount);
}
OnGUI is called at least twice per frame. First to compute the layout and then to actually draw the GUI. Try to do a
Debug.Log(Time.frameCount + ": " + Event.current);
To get a better understanding of the call structure.
thanks.
perhaps that detail should be added to the documentation? ![]()
OnGUI can be called many times per frame. The GUI system does different things when OnGUI gets called - first it does a prepare pass, recording what components are there (so tab order can be figured out, GUILayout positions are calculated, etc). Then it does the actual event processing; MouseDown, MouseUp, KeyDown, KeyUp, Repaint.
to see what it’s actually doing, take a look at Event.current.type
I came across this because I was trying to figure when the mouse was over a GUI component so I could ignore mouse events on the 3d objects in the background.
I could not find anything that would give me that, the closest was GUIUtility.hotControl.
I had to store the rects of the gui areas to test when the user click with Rect.Contains() to get it to work.
it would be useful if GUIUtility had a flag that would be set when the mouse over a gui element somenthing like GUIUtility.mouseOver or something like that.
That is solved in the next Unity release