Author Topic: Optimization Issues (here's what profiler shows)  (Read 3289 times)

bigproblem01

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Optimization Issues (here's what profiler shows)
« on: November 03, 2014, 11:53:23 AM »
Hi,

I've been having some lag issues on the iOS devices (it's not really noticeable on PC).

My situation is the following:
I have an invisible widget (Let's call it "Game") that has a lot of children.
More specifically "Game" has 90 invisible widgets as children which in turn each have their own children and all those also have a collider on them because they need to be buttons. In case you're wondering why the hell I'd need 90 buttons on a regular UI, it's a board game made in NGUI.

There's a function that programmatically generates the aforementioned "Game" gameobject and this function is called in Unity's Awake().
The "Game" gameobject itself is inactive at the start but the generation happens nonetheless without a problem.
When the player presses play, that's when the "Game" gets activated and that's when I get a huge spike in profiler and a lag on devices.
In profiler, it says that UIWidget.CreatePanel()'s and UIPanel.UpdateSelf() are responsible for this lag.

I'm attaching a profiler screenshot below in hopes that someone can explain to me what am I doing wrong optimization-wise.
Is NGUI not designed to handle such amount of widgets at once or am I the one to blame for not using it correctly?

P.S. I did find a work around by having "Game" enabled at the beginning and disabling it at the end of the first Update() cycle, but I would still like to understand NGUI better and prevent such cases from happening in the future.

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Optimization Issues (here's what profiler shows)
« Reply #1 on: November 04, 2014, 09:46:24 AM »
When you enable a widget, it needs to find the panel responsible for it and add itself to its list. Later that same frame the panel takes all the added widgets and generates draw calls for them by filling all the buffers. The first time you do it there is quite a bit of allocation involved as buffers are created/resized/uploaded to Unity. There is no avoiding this.

bigproblem01

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Optimization Issues (here's what profiler shows)
« Reply #2 on: November 04, 2014, 10:32:14 AM »
I see, so all's done the way it should be then.
Thanks, useful to know that the first time one enables a widget, all this is going on. Might be a good idea to enable everything on game startup and disable whatever's not needed just to be safe.