Author Topic: UIPlayTween Behaviour in NGUI 3.0.0c  (Read 9088 times)

Cloun

  • Guest
UIPlayTween Behaviour in NGUI 3.0.0c
« on: September 24, 2013, 07:32:09 AM »
There seems to be an inconsistency in NGUI 3.0.0c when using UIPlayTween's.  I believe the fix is relatively simple but thought I'd question the behaviour before putting up a pull request.

The issue seems to be how and when a play tween resets when the tween has finished and the following use cases should show the behaviour

First Use Case
* Create a UIPlayTween that triggers a Tween Position
* Set the UIPlayTween properties Direction: Forward, If Disabled: Enable, If Playing: Restart, When Finished: Don't disable
* Trigger the tween, let it finish

Triggering it again shows the problem.  It begins at the start point, but doesn't perform the tween.  I believe this is due to 'if (resetOnPlay) tw.Reset();' in UIPlayTween.cs being on line 271 rather than 267 (making this change fixes the problem).

Second Use Case
* Create a UIPlayTween that triggers a Tween Position
* Set the UIPlayTween properties Direction: Forward, If Disabled: Enable, If Playing: Continue, When Finished: Don't disable
* Trigger the tween, let it finish

Triggering it again shows another problem.  It doesn't replay the tween, it just places the widget at the end of the tween.  I assume this is because of the 'If Playing: Continue' but the tween is not playing, it's finished.

I expected the behaviour of this to be
* If never played, plays from start to finish
* If in the middle of playing, continues from where it is (i.e. ignored the additional play)
* If finished, it replays the tween from the start

At the moment I can't get this behaviour.  If I set 'If Playing: Restart', the first and last points work (with the bug fix from the first point anyway) but the second will restart the tween rather than ignore it.

From the naming of the property (If Playing), I'd expect it to restart from the beginning once it's finished as it is no longer playing.

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPlayTween Behaviour in NGUI 3.0.0c
« Reply #1 on: September 24, 2013, 01:01:07 PM »
You are right on both counts.

Change that part to the following, and you will get the result you're expecting:
  1.                                         // Toggle or activate the tween component
  2.                                         if (playDirection == Direction.Toggle)
  3.                                         {
  4.                                                 tw.Toggle();
  5.                                         }
  6.                                         else
  7.                                         {
  8.                                                 if (resetOnPlay || !tw.enabled) tw.Reset();
  9.                                                 tw.Play(forward);
  10.                                         }

SirManGuy

  • Guest
Re: UIPlayTween Behaviour in NGUI 3.0.0c
« Reply #2 on: December 12, 2013, 04:03:52 PM »
I hate dragging up old posts but I had a similar instance with a different set up. I've got a Tween Scale (1,1,1) -> (1.3,1.3,1.3) at a speed of 0.2f and a Tween Scale of (1.3,1.3,1.3) -> (1,1,1) at a speed of 0.2f with a delay of 0.25f. With this I was noticing that the second time it was firing it would resize to 1.3,1.3,1.3 instantly on the play and then start playing the first tween.

What was happening was that the .Sample() class was firing OnUpdate() of the object without checking the mStarted variable. I've wrapped the OnUpdate() with if (mStarted) for now but I'm wondering if this is bad form with your design due to one of the other Tweens requiring OnUpdate() to fire on a reset before the actual playing happens?

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPlayTween Behaviour in NGUI 3.0.0c
« Reply #3 on: December 13, 2013, 05:03:35 AM »
What version of NGUI, and how can I repro the issue?

SirManGuy

  • Guest
Re: UIPlayTween Behaviour in NGUI 3.0.0c
« Reply #4 on: December 13, 2013, 11:58:03 AM »
With 3.0.7 rc2 I had a slightly ugly set up:
GameObject (Cube)
 -[] Tween Scale
   - (1,1,1) -> (1.3,1.3,1.3)
   - Speed: 0.2f
 -[] Tween Scale
   - (1.3,1.3,1.3) -> (1,1,1)
   - Speed: 0.2f
   - Delay: 0.25f
Camera
 - Play Tween
 - OnClick -> ScreenToWorldPoint() -> Raycast -> if we hit our GameObject run PlayTween.target = Cube

I could have set this up with an animation curve however I found I got the exact results this way. What this would do is the first time run correctly by growing and shrinking the object with the timing I was after. The second time the UITween.Reset() fires .Sample() which at the end of the function runs OnUpdate(). OnUpdate() of TweenScale resizes to the "from" Vector3. Which in my sample resizes to 1,1,1 then resizes to 1.3,1.3,1.3 then the first TweenScale fires and starts resizing the object. This creates a twitch like effect which I wasn't quite after ;). To repair I just made sure that Sample() only fired OnUpdate() if we have actually started the UITween. I'm worried though that my "fix" might cause a problem with intended functionality of another tween set up.

Modification in UITweener.cs:
  1. Line: 269        if (mStarted)
  2. Line: 270                   OnUpdate((animationCurve != null) ? animationCurve.Evaluate(val) : val, isFinished);
  3.  

Let me know if you need me to set up a project and send it to you; I'd be happy to help.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPlayTween Behaviour in NGUI 3.0.0c
« Reply #5 on: December 13, 2013, 12:49:41 PM »
Ah, you're triggering both at the same time -- that's why you are running into this.

You need to use the OnFinished field of one to trigger the other.

Or... better yet -- just use only one. Set up its curve so it's shaped like an inverted "U".

Zephire

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIPlayTween Behaviour in NGUI 3.0.0c
« Reply #6 on: July 29, 2014, 01:14:22 PM »
Hi ArenMook,

Sorry for digging up this one, but after searching the forums the OP's second example is exactly what I'm currently facing (using NGUI v3.6.8)

1. Setup a UIPlay Tween with the trigger condition: On Hover True, Tween group 0. Tween Scale From 1.00 To 1.75 on all values, Tween group 0.
2. Setup a UIPlay Tween with the trigger condition: On Hover False, Tween group 1. Tween Scale From 1.75 to 1.00 on all values, Tween group 1.

First time I hover over it works fine, hover out perfect as well. But after that it jumps straight away in the scale I've defined.

Would the solution you mentioned also help avoid this? If so in which script should I adjust this?

Thanks in advance!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPlayTween Behaviour in NGUI 3.0.0c
« Reply #7 on: July 30, 2014, 10:10:43 AM »
The curve is specified on the tween itself. It's completely linear by default -- a straight line from bottom left to top-right.

Tween Group should not be 0 btw. 0 means "no group". If you want it to work consistently, use non-zero values.

Zephire

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIPlayTween Behaviour in NGUI 3.0.0c
« Reply #8 on: July 30, 2014, 11:22:35 AM »
Hi ArenMook,

Thanks for the quick reply. I've adjusted the groups not using the 0 reference any more.

However the issue I have doesn't seem to originate from the curve setting. The tween plays perfectly on the first mouseover and when moving away again it plays perfectly as well. It's all consecutive times after the first that it seems to be ignoring the tween it should be utilising.