Search Unity

Code entering/exiting a playable behaviour on the graph?

Discussion in 'Timeline' started by Silly_Rollo, Jun 6, 2019.

  1. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    I'm trying a simple experiment with Timeline. I have custom classes inheriting from PlayableBehaviour/PlayableAsset and I want to fire off code when entering and exiting them when playing the graph. Is there no straight forward way to do that? (I don't want to use signals for various reasons).

    Using OnBehaviourPlay / OnBehaviourPause sorta works but they also get called a number of other times. OnBehaviourPlay also does not get called when a behavior is on frame 0. I can correct that by starting everything on frame 1 but that is asking for bugs.

    For visual aid


    I have debug events on OnBehaviourPlay / OnBehaviourPause. When I play I would expect to get 1 play, 1 pause, 2 play, 2 pause, 3 play, 3 pause.
    Instead I get (nothing).. 1 pause, 2 play, 2 pause, 3 play, 3 pause, 1 pause

    How can I get simple enter/exits?

    edit: It's also possible all of this is goofy because of the editor. Like any time I click on the gameobject with a director I get the OnGraphStart events for everything. When it finishes playing it also does the OnGraphStop and OnGraphStart events back to back. If it's more consistent when compiled that will still make it a pain to develop.

    edit2: figured out my Marker issue. It was a serializable problem. Markers + events seem more consistent than playables but they are harder to position. I kinda wanted events that couldn't overlap but maybe I'll put up with markers as they are.
     
    Last edited: Jun 6, 2019
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    The expected order is 1 pause (initialization), 1 play, 1 pause, 2 play, 2 pause, 3 play, 3 pause. The first evaluation of the timeline does not necessarily start at 0, so you may get 1 play not at frame 0. And a large jump (which can happen during frames with a lot of processing) could cause it to skip altogether.

    If you need guaranteed triggers, signals/markers are the correct solution. Clips are intended to do deterministic evaluation.
     
  3. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    So markers will always get triggered even if timeline starts skipping due to low fps?
     
  4. julienb

    julienb

    Unity Technologies

    Joined:
    Sep 9, 2016
    Posts:
    177
    Yes this is correct.
     
  5. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    Is there a way to get the marker to run its own code when triggered? (not require a listener to receive anything)