Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Help with Understanding Timeline Stopped Action

Discussion in 'Timeline' started by rushk1, Jan 24, 2019.

  1. rushk1

    rushk1

    Joined:
    Sep 24, 2017
    Posts:
    39
    The code below is working correctly, I looked at the sample code in the Scripting Documentation , just want to understand why the function signature requires a PlayableDirector . As a beginner to scripting , I tried reading about Action Delegates as well , but I can't figure it out, would really help to understand the logic for why the Playable Director Argument is required.
    Thanks
    Code (CSharp):
    1.  void OnEnable()
    2.     {
    3.    
    4.         resetDirector.stopped += OnPlayableDirectorStopped;
    5.    
    6.     }
    7.  
    8.     private void OnPlayableDirectorStopped(PlayableDirector a)  //Why is this Argument required
    9.     {
    10.         if (resetDirector == a) //Why is this required?
    11.         {
    12.            //Do Something
    13.         }
    14.     }
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,313
    In the use case you have, it's not really necessary. It's there so you if you register one callback to multiple playable directors (e.g. from a manager-type class), you know which playableDirector was stopped.
     
    rushk1 likes this.
  3. rushk1

    rushk1

    Joined:
    Sep 24, 2017
    Posts:
    39
    Got it, thank you very much!
     
  4. rushk1

    rushk1

    Joined:
    Sep 24, 2017
    Posts:
    39
    If this is done then
    Code (CSharp):
    1. void OnEnable()
    2.     {
    3.  
    4.         resetDirector.stopped += OnPlayableDirectorStopped;
    5.  
    6.     }

    after the first
    time that the Playable Director is played using PlayableDirector.Play(),
    it automatically plays sometimes (I can't figure out whatis causing it to play) even though Play On Awake is false and PlayableDirector.Play() this is not called.

    If this is done then

    Code (CSharp):
    1. void Awake()
    2.     {
    3.  
    4.         resetDirector.stopped += OnPlayableDirectorStopped;
    5.  
    6.     }
    then it plays as expected that is only when PlayableDirector.Play() is called.


    Is this how it is supposed to be ?
     
    Last edited: Jan 26, 2019
  5. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,313
    I'm not sure why the playable director would be getting played if you use OnEnable(). That's strange.

    I would expect setting it from Awake() to work better, as OnEnable() is called later, and possibly more often.
     
unityunity