Search Unity

  1. We want you to join us at GDC this year! Take a peek at all of the events we will be hosting during the week of GDC.
    Dismiss Notice
  2. Tell us about your experience here and you’ll get early access to the 2018 Game Studios report + more goodies.
    Dismiss Notice
  3. Unity 2017.3 has arrived! Read about it here.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  5. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice

Editor Scripts OnGUI()

Discussion in 'Scripting' started by Homicide, Feb 13, 2018.

  1. Homicide


    Oct 11, 2012
    Hi guys. Im curious. Assuming i have something simple such as a custom editor window with a toggle set up to turn on or off a light...

    if im correct, the OnGUI happens with each action, for eg movement of the mouse on screen, etc.

    So i noticed that Debug.Log will tell me with each stroke of the mouse over and over "lights off" after i toggle 'turn off' the lights, and i got to thinking, is it really running a routine each and every single frame OnGUI does something? Attempting to turn off all the lights again and again.... it just doesnt seem optimal, so i assume im doing something completely wrong.

    thanks, bit newish here.
  2. johne5


    Dec 4, 2011
    yes, that's correct, OnGui is ran every frame.
  3. Aurimas-Cernius


    Unity Technologies

    Jul 31, 2013
    It's run every frame, but can be multiple times per frame as it is run for every input event that happened that frame too.
  4. NA-RA-KU


    May 5, 2013
    Yeah, it will assign fields every frame.
    If you are using a public property to call a function, you should check whether the value has changed first.