Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Wisteso on May 15, 2014, 04:04:57 PM

Title: TweenAlpha's onFinished being called immediately, not after finished [Solved]
Post by: Wisteso on May 15, 2014, 04:04:57 PM
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
Title: Re: TweenAlpha's onFinished being called immediately, not after finished
Post by: Wisteso on May 15, 2014, 04:40:07 PM
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