Author Topic: Two TweenPosition problems  (Read 9926 times)

markbsfs

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 19
    • View Profile
Two TweenPosition problems
« 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


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Two TweenPosition problems
« Reply #1 on: February 27, 2014, 06:10:26 PM »
Is the panel marked as Static?

markbsfs

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 19
    • View Profile
Re: Two TweenPosition problems
« Reply #2 on: February 27, 2014, 06:14:47 PM »
No, it is not marked as static

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Two TweenPosition problems
« Reply #3 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.

markbsfs

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 19
    • View Profile
Re: Two TweenPosition problems
« Reply #4 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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Two TweenPosition problems
« Reply #5 on: February 27, 2014, 06:38:33 PM »
I strongly advise updating to the latest version.

markbsfs

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 19
    • View Profile
Re: Two TweenPosition problems
« Reply #6 on: February 27, 2014, 06:39:45 PM »
Okay, will do

markbsfs

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 19
    • View Profile
Re: Two TweenPosition problems
« Reply #7 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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Two TweenPosition problems
« Reply #8 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).

markbsfs

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 19
    • View Profile
Re: Two TweenPosition problems
« Reply #9 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

markbsfs

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 19
    • View Profile
Re: Two TweenPosition problems
« Reply #10 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?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Two TweenPosition problems
« Reply #11 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...?

markbsfs

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 19
    • View Profile
Re: Two TweenPosition problems
« Reply #12 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Two TweenPosition problems
« Reply #13 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?

markbsfs

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 19
    • View Profile
Re: Two TweenPosition problems
« Reply #14 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.