Search Unity

Timeline Playable Behaviour Callbacks

Discussion in 'Timeline' started by lingumigeorge, Sep 4, 2018.

  1. lingumigeorge

    lingumigeorge

    Joined:
    Nov 21, 2016
    Posts:
    7
    Hi,

    I was wondering what the expected behaviour of the PlayableBehaviour callbacks are e.g. `OnBehaviourPlay`. This is especially confusing with the handling of both Edit-time/Run-time.

    I'm new to Timeline and the PlayableGraph, so at the moment the problem I'm coming up against is when calling `PlayableDirector.Pause`/`PlayableDirector.Resume`.

    Essentially, I would like to be able to differentiate between when a Playable is paused because it's finished playing and when it's paused because the PlayableDirector is paused. Is there a way to do that?

    My current hack is to:

    1. On Play/First Frame, save the director's current time
    2. On Pause, see if the clip is over by assessing the `startTime` + `playable.GetDuration()` > `time`

    There is also the mysterious `IsDone()` flag which seems to never get set (in my brief testing).

    In general it would be great to get a rundown of when:

    - `OnBehaviourPause`
    - `OnBehaviourPlay`
    - `OnProcessFrame`
    - `OnGraphStart`
    - `OnGraphStop`

    [reliably] get called, and in which order. I noticed `OnGraphStop` gets called when the director pauses, and `OnBehaviourPause` seems to get called when the scene loads (although I haven't fully tested/isolated that to confirm).

    Apologies if these are basic questions, this is my first experience with Timeline and am looking to see how to fit it into our current workflow.

    Thanks!
     
    a_20200529 likes this.
  2. lingumigeorge

    lingumigeorge

    Joined:
    Nov 21, 2016
    Posts:
    7
    After playing around with it a bit more I think I have "working" solution which is to use the director's play state. So, if `OnBehaviourPause` is called, then:

    - if the director is paused, it means pause
    - if the director is playing, it means over

    I haven't tested this thoroughly for it to be reliable, but logically (assuming the definition of `OnBehaviourPause`) it would seem to work.
     
  3. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    • OnBehaviourPause - Called when the clip becomes deactivated. This occurs when the timeline starts, when the clip is passed it's duration, or if the timeline is stopped.
    • OnBehaviourPlay - Called when the clip activates. This may be preceded by a Pause call when the timeline starts even if the clip is on the first frame
    • OnProcessFrame - Called every frame the clip is active.
    • OnGraphStart - Called when the timeline starts playing, or before the first evaluate.
    • OnGraphStop - Called when the timeline stops playing.
    OnGraphStart and OnGraphStop can be quite deceiving in Editor because the underlying PlayableGraph (which is the instance of the timeline) is frequently rebuild as the timeline is edited.
     
  4. lingumigeorge

    lingumigeorge

    Joined:
    Nov 21, 2016
    Posts:
    7
    Thanks!

    It woudl be great to get more events, such as onComplete or on ReachedEnd etc .
     
  5. tonycoculuzzi

    tonycoculuzzi

    Joined:
    Jun 2, 2011
    Posts:
    301
    This is sorely needed.
     
  6. TheHeftyCoder

    TheHeftyCoder

    Joined:
    Oct 29, 2016
    Posts:
    91
    Necroposting, but just wanted to say that I've seen OnBehaviourPause not being called after the clip ends, but only when the timeline starts. It happens, but not all the time. Clip is small, 3 frames duration if that helps.
     
  7. wqaetly

    wqaetly

    Joined:
    Oct 25, 2018
    Posts:
    7
    This is too counterintuitive! Why would OnBehaviourPause be called when the timeline starts playing? I think the programmers responsible for designing the lifecycle architecture should be kicked out.
     
  8. cz-ds

    cz-ds

    Joined:
    Nov 10, 2021
    Posts:
    5
    Is there are reliable way to use OnBehaviourPause as clips end? It gets called when the timeline starts as well..
    So It'd be fine if there is some condition to check if it is when timeline starts or clip ends
    Code (CSharp):
    1.             public override void OnBehaviourPause(Playable playable, FrameData info){
    2.                 // check where we are
    3.             }
    4.