Author Topic: Tweens sharing events?  (Read 2543 times)

dillrye

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 30
    • View Profile
Tweens sharing events?
« on: February 03, 2014, 12:32:41 PM »
Hello, I am currently doing two seperate animations for an open/close ui event, and I noticed that it seems events from previous tweens are being called even though I am doing a new Tween.Begin().

Note: Both tweens are not running at the same time, but are attached to the same root game object.

First Tween:
TweenPosition tween = TweenPosition.Begin(this.gameObject, 0.30f, new Vector3(0.0f, 615.0f, this.transform.localPosition.z));
EventDelegate.Add(tween.onFinished, HideTweenFinished);

Second Event:
TweenPosition tween = TweenPosition.Begin(this.gameObject, 0.30f, new Vector3(0.0f, 0.0f, this.transform.localPosition.z));
EventDelegate.Add(tween.onFinished, ShowTweenFinished);

After calling the first tween, the second tween will call both ShowTweenFinished, and HideTweenFinished when I would expect it to only call the event passed to it.  I am able to remedy the problem by calling Clear() on the event list for the specific tween, but this seems like a bug to me.

Thank you,
Dylan

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tweens sharing events?
« Reply #1 on: February 04, 2014, 02:36:01 AM »
You're adding event delegates permanently. You need to add them as one-shot by passing 'true' for the last parameter, like so:
  1. EventDelegate.Add(tween.onFinished, HideTweenFinished, true);
This way they will be removed from the list after executing once.