Author Topic: TweenPosition with 0 duration broken?  (Read 2244 times)

dlewis

  • Guest
TweenPosition with 0 duration broken?
« on: October 22, 2012, 11:52:34 PM »
I've just updated from 2.1.6 to 2.3.3 and my tweens are broken. Whenever I attempt to use TweenPosition with a duration of 0 the object gets set to (0, 0, 0).

I started a blank project, downloaded a clean version of NGUI and it still doesn't work. If I have a duration of anything other than 0 it works. I've tried investigating it myself but I haven't had much luck figuring out what's different in the working version vs the broken version.

The only thing odd I have seen is that the OnUpdate function in TweenPosition doesn't seem to work for 0 duration. The problem with the code (below) is that the to and from positions are never set until after the tween has been created so cachedTransform will always be (0, 0, 0) for a tween with 0 duration.

  1. override protected void OnUpdate (float factor, bool isFinished) { cachedTransform.localPosition = from * (1f - factor) + to * factor; }
  2.  

Any ideas?

edit: Here is my super simple example script that I'm using in the empty project as reference

  1. Vector3 newPos = go.transform.localPosition;
  2. if (toggle) newPos.y -= 300.0f;
  3. else newPos.y += 300.0f;
  4. TweenPosition.Begin(go, 0f, newPos);

edit2: I should mention I'm on Unity beta 12. If no one else has this issue I'm pointing the finger straight at Unity.
« Last Edit: October 23, 2012, 12:05:56 AM by dlewis »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TweenPosition with 0 duration broken?
« Reply #1 on: October 23, 2012, 01:38:47 AM »
While I question the point of having a tween with duration of 0 (why not just move the object?), you're right at there is an issue here.

I've modified my local version, but if you want to fix it on your end, modify TweenPosition's Begin function, and add this before the return statement:
  1. if (duration <= 0f)
  2. {
  3.         comp.Sample(1f, true);
  4.         comp.enabled = false;
  5. }