Author Topic: Offscreen panels, how to not impact CPU?  (Read 3256 times)

jerotas

  • Guest
Offscreen panels, how to not impact CPU?
« on: October 05, 2012, 01:04:28 PM »
Hi guys,

I have about 7 NGUI panels in my main game scene. Normally only the main HUD panel is onscreen, but profiler is telling me that UIPanel.LateUpdate is taking 10+ ms per frame on my iPhone 3GS, which seems excessive to me. Also I have UIWidget.Update taking 2ms. Anything I should look for to improve this? AIs there a way I can add some code that will stop offscreen panels from using CPU? Most of these panels are not able to be marked as "static" because things move around when they are onscreen and that doesn't work with static.

I was going to use NGUITool.SetActive to disable them all at the beginning of the scene, and enable them when needed, but apparently you can't enable after disabling...so do I need to spawn and despawn my panel dialogs to save CPU? Is there any other way?

Thank you!
« Last Edit: October 05, 2012, 03:41:15 PM by jerotas »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Offscreen panels, how to not impact CPU?
« Reply #1 on: October 05, 2012, 06:12:17 PM »
Can't enable after disabling? Wuh? I always do this in Windward -- ActiveAnimation animates panels, moving them off-screen and disables them. You can do the same with any tween.

jerotas

  • Guest
Re: Offscreen panels, how to not impact CPU?
« Reply #2 on: October 05, 2012, 06:32:27 PM »
Can't enable after disabling? Wuh? I always do this in Windward -- ActiveAnimation animates panels, moving them off-screen and disables them. You can do the same with any tween.
I am setting the game object containing the UiPanel to inactive with that call. You cannot subsequently set it to active because Unity considers it to not exist at that point. I even saw you post this same observation in another thread here. What is a tween anyway? I don't know what Windward is. Do I have to use that to do this?

I am considering spawning and despawning my panels with PoolManager to get around this, but let me know if there's a different way.
« Last Edit: October 05, 2012, 06:34:18 PM by jerotas »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Offscreen panels, how to not impact CPU?
« Reply #3 on: October 05, 2012, 06:59:08 PM »
You need to use NGUITools.SetActive to activate / deactivate UI hierarchies. Setting GameObject.active is deprecated in Unity 4.0. When you disable a game object, scripts on that object no longer work. You need to have your scripts elsewhere if you want to activate a disabled object -- not on that object.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Offscreen panels, how to not impact CPU?
« Reply #4 on: October 05, 2012, 06:59:29 PM »
As for what's Windward: http://www.tasharen.com/windward/

jerotas

  • Guest
Re: Offscreen panels, how to not impact CPU?
« Reply #5 on: October 06, 2012, 03:08:01 AM »
Thanks Aron,

I swear I was using the NGUITools.SetActive and it wouldn't let me turn it back on, but it appears to be working now. Weird!