Search Unity

How to avoid GUI.Repaint spikes

Discussion in 'Immediate Mode GUI (IMGUI)' started by Suvajit, Jun 7, 2013.

  1. Suvajit

    Suvajit

    Joined:
    Nov 19, 2012
    Posts:
    4
    I am getting GUI.Repaint->Event.Internal_MakeMasterEventCurrent() spikes (60 ms) when profiling on an android device on every 40th frame approximately.
    I am not using OnGUI() method call in any of my scripts. Is there any way to totally remove the GUI.Repaint spikes.

    $Screen Shot 2013-06-07 at 2.40.23 PM.png $Screen Shot 2013-06-07 at 2.41.00 PM.png
     
  2. dkozar

    dkozar

    Joined:
    Nov 30, 2009
    Posts:
    1,410
    Allegedly it's not enough to disable the script containing th OnGUI call - you have to remove it. Perhaps that helps?
     
  3. Suvajit

    Suvajit

    Joined:
    Nov 19, 2012
    Posts:
    4
    Now I have commented out all OnGUI methods. However It has not helped much. I am heavily using TextMesh with dynamic font. Could it be because of that ?
     
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Is that a Deep profile?
     
  5. Suvajit

    Suvajit

    Joined:
    Nov 19, 2012
    Posts:
    4
    Yes
     
  6. faceOFF

    faceOFF

    Joined:
    Jul 19, 2012
    Posts:
    20
    I have similar issue while, general I don't use Unity GUI, my interface entirely in NGUI, why do I have a spike in 36ms from GUI.Repaint -> GUIUtility.EndGUI (). Is there any way to disable totally buggy and brake standard Unity GUI?
     
  7. taimur_azhar

    taimur_azhar

    Joined:
    Mar 19, 2015
    Posts:
    7
    its (2018) and Still i face this problem
     
    JohannesGans likes this.
  8. Deleted User

    Deleted User

    Guest

    Hi Guys,

    I don't have OnGUI() anywhere in my entire project but still get 384B GC Alloc. My Unity version is 2017.3.0f3, Please help me. The only thing I used are UI Text & UI Image, Please Help

    Thanks & Regards,
    Bhanu
     
  9. rahulk1991

    rahulk1991

    Joined:
    Feb 22, 2019
    Posts:
    12
    I don't have onGUI and still see GUI.Repaint spikes.. I'm on 2019.1.8f, can someone explain how to reduce the cpu usage by GUI.Repaint?
     
  10. merpheus

    merpheus

    Joined:
    Mar 5, 2013
    Posts:
    202
    Same here.
     
    rahulk1991 likes this.
  11. mikapote

    mikapote

    Joined:
    Oct 24, 2018
    Posts:
    28
    Same here, 2019.3.0.
     
  12. mariosgakuto

    mariosgakuto

    Joined:
    Oct 18, 2015
    Posts:
    14
    Same here.
     
  13. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    90ms at constant spikes for about 10sec - happens about every 2-10min even if the Editor is not focused, I can watch youtube videos in a browser not paying attention to unity being open and I will still get the lag.
    What exactly is happening here and how to avoid it? It seems to be the scene view, inspector view and hierarchy view.
    I'll make further test, closing all those editor tabs to see if the lag is still happening.

    upload_2020-5-1_6-25-57.png
     
  14. nizameddinkale

    nizameddinkale

    Joined:
    Mar 1, 2019
    Posts:
    1
    Did you solved it?
     
  15. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    IMGUI is quite slow, so I still have some troubles getting a stable framerate when the inspector is open but the >10sec spikes were caused by my damaged graphics card.
    I had to change the cooler because it was constantly overheating ... idk why it only happend when Unity was open and not when playing games.
    Upgrading to 2020.1 also was a big speedup, the scene view is just way faster now, as well as opening scripts in the inspector - everything feels more responsive than back then. If you face the same issue, check your GPU.

    PS: Later I had a "delegate leak" in a custom debug drawing system I wrote, which was calling CustomDrawGizmo() and CustomDrawHandles() on all monobehaviours in the scene which also caused extreme lags. Basically I was drawing all Gizmos and Handles for all Objects in the Scene 100+ times per Editor Update Tick - but making the same mistake as I did is quite unlikely.
    Fun Fact: I wrote the system to increase the performance because putting an if() condition into the OnDrawGizmos() Method can kill the performance when you have lots and lots of objects with potential gizmos to draw.
     
    Last edited: Sep 22, 2020
    nizameddinkale likes this.
  16. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Anyone found a solution for this nasty problem?
     
  17. SquaLLio

    SquaLLio

    Joined:
    Jun 16, 2019
    Posts:
    9
  18. Hossein5017

    Hossein5017

    Joined:
    Oct 9, 2017
    Posts:
    4
    the unity 2020 is bullsheet every time has opening has erorr for proxy collobrate or other package
    asset store in package manager not work and again is bullsheet
    old version is so better
    . always has repaint all wtf ........................
    i tired that unity version
    unity 2018 is so better
     
  19. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    In my case, Rewired was making a problem. I had OnGui turned on, it all works now.
     
  20. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    Im getting this too on a really simple scene. If I click aroudn the ui and tunr things off and one randmly it suddenly goes away, but that is very annoying, any solution ?
     
  21. pavelkingx

    pavelkingx

    Joined:
    Mar 3, 2021
    Posts:
    2
    2021 still the same problem
     
  22. bonggoo8

    bonggoo8

    Joined:
    Feb 23, 2021
    Posts:
    1
    This is not a 100% fix but I was able to reduce the magnitude of the spikes, thus mitigating their impact during profiling. First, turn off any profiler modules you don't need (ie turn off GPU/memory if you are mainly concerned with cpu usage). Next, reduce the number of windows you have open in the editor. Each one will take time in the editor loop to render. So if you have a game view + scene view + inspector window with transform updating in real time + debug console, that gets to be a lot. Hope this helps.
     
    JohannesGans and radiantboy like this.
  23. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    Yes I wish they would do repainting of unity ui in a diferent thread, or optimise it or something. Seems ludicrous to me that an object with 10 scripts can slow game down over 50%. Also you mention profiler modules, what exactly do you mean? All I know of is the profiler itself.
     
  24. Fuzzypup

    Fuzzypup

    Joined:
    Aug 13, 2013
    Posts:
    190
    Are you saying you have 10 scripts with 10 OnGui() statements?

    Why not make a single OnGui() manager object with a single OnGui() statement.
     
  25. Ate-Games

    Ate-Games

    Joined:
    Jan 13, 2021
    Posts:
    4
    In my case it seems related to Unity ads when i show a rewarded video the gui.repaint is taking 368 B alloc
     
  26. donovand4

    donovand4

    Joined:
    May 8, 2013
    Posts:
    9
    I have the same issue with the GUIRepaint. If I disable the adverts scripts it goes away.
     
  27. aelborke18

    aelborke18

    Joined:
    Oct 21, 2018
    Posts:
    1
    I don't have any OnGUI(); function in my project. once I added a rewarded ad to the project I start getting a big spike on the GUI.repaint gc alloc. I used the same rewarded ad script provided by unity. it seems like that is the problem.
     
  28. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    504
    Are you guys using Debug.Draw?

    I just disabled some of my debug gizmo and the GUI related garbage is completely gone.
     
    devdepot likes this.
  29. ruudvangaal

    ruudvangaal

    Joined:
    May 15, 2017
    Posts:
    27
    In Unity 2021.3, reducing the number of enabled OnGUI() scripts to 0 will still call GUI.Repaint() but the time spent is around 0.01ms now, so acceptable.