Author Topic: UIRect.Start called one frame late  (Read 2386 times)

Charriu84

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 9
    • View Profile
UIRect.Start called one frame late
« 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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIRect.Start called one frame late
« Reply #1 on: September 24, 2017, 01:37:18 AM »
Call NGUITools.ImmediatelyRefreshDrawCalls on the game object you've just activated.

Charriu84

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: UIRect.Start called one frame late
« Reply #2 on: September 25, 2017, 03:36:36 AM »
Thanks. That solved it  ;D