Author Topic: [Bug] creating new tweens on the same object will not reset eventReceiver  (Read 2524 times)

tayl0r

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
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?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
You're right, I'll patch it in.

tayl0r

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
While you're at it, it would be nice to make an overloaded method for Begin that also accepts eventReceiver and callWhenFinished parameters =)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Why? The tween is returned to you, letting you set the event receiver.