Author Topic: Why isn't there an UpdateManager?  (Read 1431 times)

Sahkan

  • Jr. Member
  • **
  • Thank You
  • -Given: 9
  • -Receive: 0
  • Posts: 74
    • View Profile
Why isn't there an UpdateManager?
« on: March 07, 2017, 05:52:24 AM »
I'v noticed it is recommended from several sources to use an update manager that calls the update functions in the all scripts instead of using the usual Update() function on each one.
This article is from unity's website:
https://blogs.unity3d.com/2015/12/23/1k-update-calls/

So I wonder why is there no UpdateManager for NGUI?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Why isn't there an UpdateManager?
« Reply #1 on: March 10, 2017, 11:18:30 AM »
No particular reason. You can try it yourself to see if it makes any performance difference in your project (I doubt you will ever have 10k active widgets, or even 1000 for that matter!) -- change UIRect.Update to be UIRect.CustomUpdate, then call it from UIPanel.UpdateWidgets inside the iteration loop:
  1.                 for (int i = 0, imax = widgets.Count; i < imax; ++i)
  2.                 {
  3.                         UIWidget w = widgets[i];
  4.  
  5.                         // If the widget is visible, update it
  6.                         if (w.panel == this && w.enabled)
  7.                         {
  8.                                 w.CustomUpdate();// <--
Edit: Actually there is a reason, now that I think about it... custom update like that won't be called at edit time when working with the component -- such as changing the text of a label. Unity will call Update() of the component you're changing, but it won't call Update() of another component.
« Last Edit: March 10, 2017, 11:38:37 AM by ArenMook »