Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Charriu84 on September 22, 2017, 04:28:56 AM

Title: UIRect.Start called one frame late
Post by: Charriu84 on September 22, 2017, 04:28:56 AM
I stumbled accross I cuirous problem. Right now I have the following setup.

I have a Gameobject with a UITexture. The Gameobject is disabled in the editor, so Start() and all the others only start when I activate the gameobject during runtime.

This is what I do in my code:
  1. uitexture.gameObject.SetActive(true);
  2. panel.Refresh();
  3.  

What I wanted to do is to activate the UITexture and then refresh it's panel, so that the texture is visible in the same frame. After some research I discovered that the UITexture gets added to the panel after I refresh the panel. This happens because the UIRect.Start is called after the panel refresh. I already tried setting up the Script Execution Order so that the panel is always after the UIRect, but that didn't work.
The obvious solution would be something like this:
  1. uitexture.gameObject.SetActive(true);
  2. uitexture.Start();
  3. panel.Refresh();
  4.  
But this could lead to other problems like widgets added multiple times to a panel. So now I'm wondering what would be the best way to ensure that a UIRect is initialized before calling a corresponding UIPanel.Refresh().

Thanks in advance
Title: Re: UIRect.Start called one frame late
Post by: ArenMook on September 24, 2017, 01:37:18 AM
Call NGUITools.ImmediatelyRefreshDrawCalls on the game object you've just activated.
Title: Re: UIRect.Start called one frame late
Post by: Charriu84 on September 25, 2017, 03:36:36 AM
Thanks. That solved it  ;D