Support => NGUI 3 Support => Topic started by: OmegaQueen on November 26, 2014, 07:52:53 PM
Title: [NGUI] Proper way to update widgets in code?
Post by: OmegaQueen on November 26, 2014, 07:52:53 PM
Hi,
I have a group of labels attached to one GameObject each. The labels are all under one parent object.
I want to move the parent object (from a script) and then have each label's position/collider/bounds update immediately in the next line in the script so I can perform a check on the new position before the next frame starts.
How do I do this?
I've tried using UILabel.Update(), but the values don't change. Or am I supposed to do something with the UIPanel?
Thanks
Title: Re: [NGUI] Proper way to update widgets in code?
Post by: ArenMook on November 26, 2014, 08:59:18 PM
I'm not sure I understand the question. If you move something, then its position is updated right away. What are you trying to check?
Title: Re: [NGUI] Proper way to update widgets in code?
Post by: OmegaQueen on November 27, 2014, 12:27:36 AM
Hi Aren, sorry for the poor explanation. I'll try again
So I have a bunch of UILabels that are children of an object in 3D space. I move the parent/root in 3D space using:
transform.localPosition+= adjustmentVector;
but the positions of all the children labels don't seem to update their position until the next frame. So when I use them in the next line of code after moving the label they are in the position that they were before the parent object was moved, instead of the new position.
I am assuming the labels don't update immediately because I am moving objects based on whether or not they overlapp on screen. I want to do this with a while loop:
but the program gets stuck in the while loop. If I change it to an if statement then it slowly works over time and the Intersections() method returns 0 when nothing is touching. So I was wondering if NGUI labels had to be updated by their panel or something after Mono Update() or something
Title: Re: [NGUI] Proper way to update widgets in code?
Post by: ArenMook on November 27, 2014, 08:48:10 PM
Well again, what are you checking? You mentioned what you're changing, but what code do you use to check whatever you're checking? If it's transform position, then it's all Unity. And it's updated right away, just like any other game object. If it's widget's corners, then that may not be, depending on a couple of factors.