I remember something about onGui being able to be run multiple times per frame, and I also seem to recall that you can check 'which state' the onGUI is being run in, so that you can do all of the intense logic in just the part that gets run once.

Does anybody know what I am talking about --- I can't seem to remember what it was called and it is making googling it a daunting task. Thanks!



"For each event OnGUI is called in the scripts; so OnGUI is potentially called multiple times per frame. Event.current corresponds to "current" event inside OnGUI call."

If you use the Event.current, and look for a given event type in the ongui, then you can have it run once per frame. Namely, looking for the 'repaint' event.

So something like:

void OnGUI(){
    if(Event.current.type != EventType.Repaint) return;
    //otherwise if currently painting the gui
    //do all this stuff
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.