Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: tayl0r on July 16, 2012, 11:32:34 AM

Title: [Bug] creating new tweens on the same object will not reset eventReceiver
Post by: tayl0r on July 16, 2012, 11:32:34 AM
I believe this is a bug.
If you create a tween on an object using TweenColor (or any of the other tweening methods), and then later on make a new tween after that first tween has finished, the new tween will have the same eventReceiver and callWhenFinished properties even if you did not set them on the new tween. This is not expected behavior and the easy fix is to just null them both out, but I believe it should be done in the UITweener class and not in our game code.

Example how to reproduce the bug:
  1.                 Color c = m_label.color;
  2.                 TweenColor tc = TweenColor.Begin(m_label.gameObject, .5f, c);
  3.                 tc.eventReceiver = this.gameObject;
  4.                 tc.callWhenFinished = "MessageDone";
  5.  

then in your MessageDone function just tween the m_label object again.
  1.                         Color c = m_label.color;
  2.                         TweenColor tc = TweenColor.Begin(m_label.gameObject, .3f, c);
  3.  

That will call the MessageDone method even though we didn't set it, since it reuses the existing tween component.
The fix is to always null out the eventReceiver and callWhenFinished properties on your tweens, but I believe that should be done in UITweener.cs line 255:

  1.         static public T Begin<T> (GameObject go, float duration) where T : UITweener
  2.         {
  3.                 T comp = go.GetComponent<T>();
  4. #if UNITY_FLASH
  5.                 if ((object)comp == null) comp = (T)go.AddComponent<T>();
  6. #else
  7.                 if (comp == null) comp = go.AddComponent<T>();
  8. #endif
  9.                 comp.duration = duration;
  10.                 comp.mFactor = 0f;
  11.                 comp.style = Style.Once;
  12.                 comp.enabled = true;
  13.                
  14. // reset the eventReceiver and callWhenFinished properties
  15.                 comp.eventReceiver = null;
  16.                 comp.callWhenFinished = null;
  17.                
  18.                 return comp;
  19.         }
  20.  

Thoughts? I am using the tweening class incorrectly?
Title: Re: [Bug] creating new tweens on the same object will not reset eventReceiver
Post by: ArenMook on July 16, 2012, 11:44:24 AM
You're right, I'll patch it in.
Title: Re: [Bug] creating new tweens on the same object will not reset eventReceiver
Post by: tayl0r on July 16, 2012, 12:42:35 PM
While you're at it, it would be nice to make an overloaded method for Begin that also accepts eventReceiver and callWhenFinished parameters =)
Title: Re: [Bug] creating new tweens on the same object will not reset eventReceiver
Post by: ArenMook on July 16, 2012, 02:39:05 PM
Why? The tween is returned to you, letting you set the event receiver.