Author Topic: NGUI Performance Issues  (Read 5041 times)

afroman

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
NGUI Performance Issues
« on: January 28, 2014, 02:03:48 PM »
I'm having serious performance issues in UIRect.Start() & UIPanel.LateUpdate(). I have a lot of labels in my UI that can be disabled & enabled depending on whether or not the shop is open. This is causing over 1.4MB of GC. This is really hurting performance in my game, any suggestions?

Cripple

  • TNP Alpha
  • Full Member
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 117
    • View Profile
Re: NGUI Performance Issues
« Reply #1 on: January 29, 2014, 03:43:22 AM »
It seems that you Destroy and Instantiate the items whenever you hide/show them because .Start() is only called once foreach Component.

You should recycle the GameObject :
  • When you want to hide an item, don't destroy it, disable the GameObject and keep the reference in a Queue
  • When you need to show an item, pop an item in your Queue, update the parameters (label text, sprits) and enable it.
  • If the Queue is empty and you need an item, just instantiate it. You can also pre instantiate as many items as you need at the start of the game.
Graphicstream Dev.

afroman

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: NGUI Performance Issues
« Reply #2 on: January 29, 2014, 11:13:58 AM »
I do. I don't destroy objects knowing that I will use it again.

I'm actually disabling the GameObjects that I don't use after initially instantiating them. It is however still a problem when I re-enable the same GameObjects again. I'm getting a whopping 3.7MB In garbage collection in UIRect.OnEnable(). Which is causing the game to run really slow, each time the shop is open.

I doubt it but would using a Queue still help with this issue? Or would this be a general GC issue I need to work around?

Cripple

  • TNP Alpha
  • Full Member
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 117
    • View Profile
Re: NGUI Performance Issues
« Reply #3 on: January 29, 2014, 11:23:22 AM »
Do you have the last version of NGUI ? Arenmook fixed some performance issues.

I see that there is 361 calls to GameObject.Activate, do you have 361 objects in your list ?

Do you really need to disable all those objets ? Can't you just disable/enable the panel when closing/opening the shop ?
Graphicstream Dev.

afroman

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: NGUI Performance Issues
« Reply #4 on: January 29, 2014, 11:35:46 AM »
Yes, I am disabling all 361 GameObjects. I'm also on the latest version 3.09.
I was disabling the GameObjects because it seemed like the only logical thing to do.

Good idea thou, I'll try that.
Thanks, I'll let you know how it goes :)

afroman

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: NGUI Performance Issues
« Reply #5 on: January 30, 2014, 10:08:49 AM »
it's fixed, significant performance improvements!

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Re: NGUI Performance Issues
« Reply #6 on: April 03, 2014, 02:16:12 AM »
Facing the same issue here, but just disabling the panel brings back the old Unity 3 issue, enabled-state is not inherited :) So this solution is not really doable for nested panels, if you don't want to manually keep track of the state... (you don't). Still gotta try out the latest version of NGUI for potential performance-gains (currently on 3.5.1 waiting for 3.5.6), but yeah inherited enabled-state of panels would be great ;) (but may break to much for current users..?).

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: NGUI Performance Issues
« Reply #7 on: April 03, 2014, 02:54:15 AM »
Instead of disabling the Panel component, you should probably disable the gameobject - then it should be inherited.

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Re: NGUI Performance Issues
« Reply #8 on: April 03, 2014, 02:58:26 AM »
Instead of disabling the Panel component, you should probably disable the gameobject - then it should be inherited.

Well of course, but that will cause massive spikes (as you talked about above) when activating a gameObject with a large number of widgets. :(
I'm on Unity 4 so yes the state is inherited, but activating a parent will then cause all child-widgets to invoke UIRect.OnEnable = partypooper.