Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: markbsfs on February 27, 2014, 06:06:28 PM

Title: Two TweenPosition problems
Post by: markbsfs on February 27, 2014, 06:06:28 PM
Hi,

I am having two problems getting TweenPosition to work properly:

1. It doesn't work on some objects properly or completely.  The two examples below are both instantiated from prefabs:

When I instantiate a UILabel alone, TweenPosition moves the object fine
When I instantiate a UISprite + Box Collider + UIImage Button + UILabel, the object moves, but the label doesn't

In the code example below, I get the Arrived log each time, but in the second case the label stays put on screen

Is there some setting or switch I am missing with respect to the label?


2. In the case of the UILabel alone, when the object gets to its destination, approximately 80% of the time it fails to stop, shooting off either up or down.  This is the code

  1.     void SomeFunction()
  2.     {
  3.         TweenPosition twp = TweenPosition.Begin(TestObject, 3.0f, new Vector3(0.0f, 100.0f, 0.0f));
  4.         EventDelegate.Add(twp.onFinished, ArrivedRoutine, true);
  5.         Debug.Log("Start Tween");
  6.     }
  7.  
  8.     void ArrivedRoutine()
  9.     {
  10.         Debug.Log("Arrived");
  11.     }
  12.  

I get both "Start Tween" and "Arrived", but the object doesn't stop moving.

Thanks

Title: Re: Two TweenPosition problems
Post by: ArenMook on February 27, 2014, 06:10:26 PM
Is the panel marked as Static?
Title: Re: Two TweenPosition problems
Post by: markbsfs on February 27, 2014, 06:14:47 PM
No, it is not marked as static
Title: Re: Two TweenPosition problems
Post by: ArenMook on February 27, 2014, 06:27:00 PM
Well, there are a few reasons why tween position wouldn't work.

1. Panel has the "static" flag, which you've ruled out. This will move the object, but not the drawn widget
2. Anchored widget using an older version of NGUI. In this case neither the widget nor the drawn object will move.
3. Something else interferes with the movement like UIButtonOffset. Same as #2: nothing will move.

Make sure you are using NGUITools.AddChild to instantiate your prefab. Tweens are linear -- they always stop when they get to the target position.
Title: Re: Two TweenPosition problems
Post by: markbsfs on February 27, 2014, 06:35:27 PM
I downloaded my version of NGUI only a month ago, so that's probably not it

I am not setting any UIButton offsets.  Are you talking about the "spacing" field in UILabel?

I am instantiating using this, though:

   TestObject = (GameObject)Instantiate(Resources.Load("TestObject"));

I will switch over and see if that fixes the problem.

As for the tweens, I was surprised when it didn't stop.  Not only that, it changed speed after it arrived.

Thanks
Title: Re: Two TweenPosition problems
Post by: ArenMook on February 27, 2014, 06:38:33 PM
I strongly advise updating to the latest version.
Title: Re: Two TweenPosition problems
Post by: markbsfs on February 27, 2014, 06:39:45 PM
Okay, will do
Title: Re: Two TweenPosition problems
Post by: markbsfs on February 27, 2014, 08:03:36 PM
Well, I upgraded to 3.5.1 and switched my instantiation to NGUITools.AddChild, but neither of these has fixed either problem.

Any other ideas?

Thanks
Title: Re: Two TweenPosition problems
Post by: ArenMook on February 28, 2014, 07:37:17 PM
Nope. If you make a repro case for me to look at, I'll look into it further. Just please don't attach/post anything here. PM me or email me the download link (support at tasharen.com).
Title: Re: Two TweenPosition problems
Post by: markbsfs on February 28, 2014, 09:36:53 PM
Okay, thanks.  I'm up to my eyes right now, so it may take me a while.

Thanks
Title: Re: Two TweenPosition problems
Post by: markbsfs on February 28, 2014, 10:49:52 PM
So, I decided to build the repro case anyway, since I have come up against the problem in a different part of the code... And I made an interesting discovery:

One again, I have a prefab: UISprite + Box Collider + UIImageButton + UILabel

When I first set it up, the text moved fine, but I couldn't see the button texture, but when I set the depth of the sprite to 2 so it would be visible, the text no longer moved.  The label is depth 4.  In fact, after further experimentation, setting the sprite's depth to *anything* (including 0) in code prevents the label text from moving.  So, there seems to be some weird interaction between a statement like this:

   ButtonSprite.depth = 2;

And the text moving along with the object in a TweenPosition.

This is the simplest possible setup, with a single script attached to an object, a background prefab, and the button prefab above.

It takes ten minutes to set up.  Do you still want me to send it to you?
Title: Re: Two TweenPosition problems
Post by: ArenMook on March 01, 2014, 08:47:57 PM
Where in the code are you changing the depth? (and why?) Is it in Awake, Start, Update...?
Title: Re: Two TweenPosition problems
Post by: markbsfs on March 01, 2014, 10:04:48 PM
I am changing the depth in Start in both cases, for the sprite and for the label.  If i don't change it for the sprite, i don't always see the different ImageButton states; if I don't change it for the label, i don't see it at all.
Title: Re: Two TweenPosition problems
Post by: ArenMook on March 02, 2014, 06:28:58 PM
So why don't you change it on the prefab to begin with? Why do this via code?

P.S. Are you aware of NGUITools.AdjustDepth?
Title: Re: Two TweenPosition problems
Post by: markbsfs on March 02, 2014, 07:56:05 PM
Because when I make things into a prefabs, the inspector removes the "depth" setting, so I no longer have access to it.

By the way, if I set the depths both to the same value, the text moves, but the imagebutton highlight behaves oddly.  If I mouse over it while it's moving, it freezes in place.  I have to move the mouse off and then back on again for the position to update.  If I set the depths to different values, the text freezes in place, but I can mouse over the imagebutton highlight while it moves just fine.

What is the advantage of NGUITools.AdjustDepth?  It looks like it operates on entire objects, not on components.  When I tried it, the label text disappeared entirely, and the imagebutton highlight froze when I moused over it, like I described above.

Title: Re: Two TweenPosition problems
Post by: ArenMook on March 02, 2014, 09:50:21 PM
NGUITools.AdjustDepth is able to adjust the depth of all widgets underneath the specified target object. So if you specify NGUITools.AdjustDepth(yourButtonGameObject, 1), it will adjust all depths by +1.

The depth should never change the behaviour like you're describing. Depth is only used for two things:
1. Draw order.
2. Event order

So if you had colliders on both the label and the button, the depth would determine which one gets the events. But freezing something in place? I'd have a closer look at the scripts you're using. If you're doing something that results in the button's position changing, then it would explain why it suddenly "freezes" in place if you have another animation on it.

For example -- if you're doing a TweenPosition on the button, and happen to have a UIButtonOffset script attached (which also uses TweenPosition under the hood).
Title: Re: Two TweenPosition problems
Post by: markbsfs on March 03, 2014, 12:23:23 AM
In my sample project I am not doing anything funny.  I made two prefabs, and used the scripts out of the box.  I have one collider.  The entire project is 60 lines of code, including comments and white space.

If I send it to you, will you look at it?  I'll provide specific instructions to demonstrate the behavior I have described.
Title: Re: Two TweenPosition problems
Post by: ArenMook on March 04, 2014, 12:09:40 AM
Yup, certainly -- support at tasharen.com. Don't post it here please.
Title: Re: Two TweenPosition problems
Post by: markbsfs on March 04, 2014, 12:31:19 AM
Will do.  Thanks
Title: Re: Two TweenPosition problems
Post by: markbsfs on March 04, 2014, 01:41:27 AM
Thanks for taking a look at my project, ArenMook.

Just to close this out, the problem was I had two widgets attached to one object.  The problem went away, after I moved the UILabel to a child object.