Author Topic: Why is UIPanel.LateUpdate entered without any conditions in the Editor?  (Read 2920 times)

bac9

  • Full Member
  • ***
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 113
    • View Profile
To be specific, I'm referring to this piece of code in UIPanel:

  1.         void LateUpdate ()
  2.         {
  3.                 #if UNITY_EDITOR
  4.                 if (mUpdateFrame != Time.frameCount || !Application.isPlaying)
  5.                 #else
  6.                 if (mUpdateFrame != Time.frameCount)
  7.                 #endif
  8.                 {
  9.                     ...

I am getting enormous, 300-400ms long interruptions in Editor window redraws every frame whenever I edit a label or move a UI widget, which is seemingly caused by this snippet above starting the redraw process for every single panel in the whole UI hierarchy if you are using the Editor (!Application.isPlaying case). Not sure why this is necessary - commenting out !Application.isPlaying case and only letting the method to continue if the first condition is satisfied doesn't seem to cause any issues whatsoever - all panels are correctly rebuilt when necessary, but widget editing is no longer triggering lag from whole UI rebuilding. Am I missing something? Is there a reason to redraw whole UI every LateUpdate in the Editor without any additional conditions?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Why is UIPanel.LateUpdate entered without any conditions in the Editor?
« Reply #1 on: December 15, 2016, 09:26:45 AM »
Time incrementing in the editor is a new change to Unity. For years now the time was effectively standing still in the editor, and was only incrementing at run time. Why are you getting 300 ms spikes here? On what, the Application.isPlaying check? If the first condition is already passing, the second will not even be considered, but even if it was why would checking isPlaying cause lag? What version of Unity is this with? I have no such issues, and my UI is already fairly extensive for the current game I'm working on.

bac9

  • Full Member
  • ***
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 113
    • View Profile
Re: Why is UIPanel.LateUpdate entered without any conditions in the Editor?
« Reply #2 on: December 15, 2016, 11:43:04 AM »
I don't think I'm getting any new behavior in terms of updates firing, it's all the same as it ever was back to oldest versions of Unity, with LateUpdate only firing when you do something in an inspector or drag something in the Scene view.
Here is what I'm encountering - you can see on the gif below how I get a spike every time I move a label:



The spike is not originating at the " || !Application.isPlaying" point, of course - it just allows the content of LateUpdate to execute every single time if you're in the Editor. As you can see here, the time taken by something starting in LateUpdate is a sum of operations on every UIPanel in the scene (I have around 40 of them to avoid redraws on move animations and such):



LateUpdate is not an endpoint where all that time is taken, of course, it's just a limit of how far profiling goes. Can't do a deep profile outside of play mode, Unity 5.5.0 seems to dislike that and crashes, but I'm fairly sure that this bit explains where all the load comes from:

  1. for (int i = 0, imax = list.Count; i < imax; ++i)
  2.     list[i].UpdateSelf();

So, my question is - why is everything updated every LateUpdate, when that's seemingly unnecessary (everything continues to update fine after I removed " || !Application.isPlaying") and triggers a costly panel update every single frame? Am I missing some hidden problem with Unity Editor that makes such a frequent and unfiltered updating of all panels necessary?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Why is UIPanel.LateUpdate entered without any conditions in the Editor?
« Reply #3 on: December 19, 2016, 10:56:55 PM »
Dunno, I'll change it on my end and see what it breaks.

bac9

  • Full Member
  • ***
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 113
    • View Profile
Thanks for wrapping this in !UNITY_5_5_OR_NEWER in the new release, that's one thing less to merge in after NGUI updates! :)