Author Topic: Flickering when calling SetActive() an GameObjects  (Read 6248 times)

Asse

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 70
    • View Profile
Flickering when calling SetActive() an GameObjects
« on: December 04, 2013, 12:09:45 AM »
Hey folks,

I get flickering when I call GameObject.SetActive(true/false) even so I call Refresh on the parent panel afterwards.

Sample project is attached.
« Last Edit: December 04, 2013, 03:03:16 PM by ArenMook »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Flickering when calling SetActive() an GameObjects
« Reply #1 on: December 04, 2013, 03:03:41 PM »
When asking for support, never post NGUI's copyrighted source code in its entirety. It's common sense. Use email instead. I ban people for this.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Flickering when calling SetActive() an GameObjects
« Reply #2 on: December 04, 2013, 05:59:09 PM »
Had a look at the provided project. Calling Refresh is not necessary, but calling CreatePanel() is, otherwise the addition of widgets to panels won't occur until the next time their Update() gets called, which may or may not be in the same frame. You should also use NGUITools.SetActive instead of Unity's method. Unity's method activates children before parents.
  1. activatedGameObject.BroadcastMessage("CreatePanel", SendMessageOptions.DontRequireReceiver);
P.S. I've just added this CreatePanel broadcast to NGUITools.SetActive so starting with the next release you won't need to call it yourself.

Asse

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 70
    • View Profile
Re: Flickering when calling SetActive() an GameObjects
« Reply #3 on: December 05, 2013, 03:52:20 AM »
Nice, this also fixed my problem with UITextures rendering wrong texture! Hope the SendMessage call won't be to expensive when you integrate it in SetActive and it's used on several objects at once.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Flickering when calling SetActive() an GameObjects
« Reply #4 on: December 05, 2013, 04:45:40 AM »
It costs a SendMessage to each child of the activatedGameObject, since that's essentially what BroadcastMessage does.

If you have many GameObjects under the activatedGameObject, or have many, many components on each of them, then it's costly. It's not free, but it won't normally kill you. ;)