Author Topic: Strange behaviour from new EventDelegate system?  (Read 3887 times)

IonRift

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Strange behaviour from new EventDelegate system?
« on: October 28, 2013, 11:29:53 AM »
I'm experiencing an unexpected behaviour from the new event system, I'm not sure if it is working as intended or not:

I've made a small test program using a clean project & v3.0.3d

when I register a call back using a UItween the EventDelegate system still calls previously registered objects with no regard for the tween instance being used.
and I can Remove a delegate using any tween instance?

(this was't the case in the 2.x system)


so this program will:

  • fade a sprite out
  • log completion of the fade
  • run a fade in
  • Log completion of the fade in; but also completion of the previous tween instance, even though the previous tween should now be out of scope?
    so now it loops, as the previous event has been called again.

The loop can be exited with a Remove, but using a temporary tween instance, no need to reference the tween used in the original registration?



  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class FadeTest : MonoBehaviour
  5. {
  6.         float fadeTime = 1f;
  7.         int fadeoutCounter = 1;
  8.        
  9.         // Use this for initialization
  10.         void Start ()
  11.         {
  12.                 fadeOut ();            
  13.         }
  14.        
  15.         public void fadeIn ()
  16.         {
  17.                 TweenAlpha twn = TweenAlpha.Begin (transform.gameObject, fadeTime, 1f);
  18.                 EventDelegate.Add (twn.onFinished, fadeInComplete);
  19.         }
  20.  
  21.         public void fadeOut ()
  22.         {
  23.                 Debug.Log ("fadeOut called once");
  24.                 TweenAlpha twn = TweenAlpha.Begin (transform.gameObject, fadeTime, 0f);
  25.                 EventDelegate.Add (twn.onFinished, fadeOutComplete);
  26.         }
  27.        
  28.        
  29.         void fadeOutComplete ()
  30.         {
  31.                 Debug.Log ("fadeOutCompleted " + fadeoutCounter + " times");
  32.                 fadeoutCounter++;
  33.                 fadeIn ();
  34.                
  35.                
  36.                 if (fadeoutCounter > 5){
  37.                         Debug.Log("running dodgy remove");
  38.                         TweenAlpha twn = TweenAlpha.Begin (transform.gameObject, fadeTime, 0f);
  39.                         EventDelegate.Remove (twn.onFinished, fadeOutComplete);
  40.                 }
  41.         }
  42.        
  43.         void fadeInComplete ()
  44.         {
  45.                 Debug.Log ("fadeInComplete ");
  46.         }
  47. }
  48.  
« Last Edit: October 28, 2013, 01:20:52 PM by IonRift »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Strange behaviour from new EventDelegate system?
« Reply #1 on: October 29, 2013, 01:03:42 AM »
Instead of EventDelegate.Add use EventDelegate.Set.

IonRift

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Strange behaviour from new EventDelegate system?
« Reply #2 on: October 29, 2013, 12:06:07 PM »
Ah fantastic, that works.

Thank you ArenMook