Author Topic: TweenAlpha's onFinished being called immediately, not after finished [Solved]  (Read 2762 times)

Wisteso

  • Full Member
  • ***
  • Thank You
  • -Given: 21
  • -Receive: 3
  • Posts: 103
    • View Profile
In my tests, I'm seeing my onFinished callback being called immediately (well 9 milliseconds later actually) after starting a tween.

It's very obvious in my tests since I have the following code...

  1.  
  2.     public void ButtonClicked(GameObject buttonObject)
  3.     {
  4.         NGUITools.SetActive(background, true, false);
  5.         Debug.Log("Before: " + System.DateTime.Now.Ticks);
  6.         backgroundTweener.PlayReverse(); // backwards for some reason
  7.     }
  8.  
  9.  

Then a different button click calls...

  1.  
  2.     backgroundTweener.PlayForward();
  3.  
  4.  

And once the tween is over, I want to disable the GameObject, so I registered the following function with the onFinished event of the Tweener...

  1.  
  2.     public void FadeCallback()
  3.     {
  4.         Debug.Log("After: " + System.DateTime.Now.Ticks);
  5.         NGUITools.SetActive(background, false, false);
  6.     }
  7.  
  8.  

However, only 90,000 ticks (9 ms) are passing even though the tween is 250 milliseconds (0.25 seconds). Everything works just fine with the SetActive calls removed, except that the GameObject is always active, of course. Everything seems to be hooked up correctly. You can clearly tell that the only issue is that the onFinished is firing immediately.

Quote
Before: 635357658363436227
After: 635357658363526232
« Last Edit: May 15, 2014, 05:49:09 PM by Wisteso »

Wisteso

  • Full Member
  • ***
  • Thank You
  • -Given: 21
  • -Receive: 3
  • Posts: 103
    • View Profile
Nope. This was programmer error.

For some reason I was thinking that onFinished would only be called at the end of my "fade out" tween. When obviously it gets callled at the end of both tweens.

Adding the line...
  1. EventDelegate.Add(backgroundTweener.onFinished, FadeCallback, true);

...right before I called...
  1. backgroundTweener.PlayForward();

...fixed the issue completely, since it would no longer be called at the end of the "fade in" tween.

/smackforehead