Access clip timings

Following the examples found in the timeline playable Wizard, I am using the new Timeline to create my own custom track which drives a monobehaviour script through a playablebehaviour.
I am adding several clips to the track and I need to access at runtime the ‘start’ and ‘end’ times of each playable inside the track. its easy to get the duration of the playable through the playableBehaviour but I really need to access the clip timings.
Your help is very much appreciated.

Ok, I sort of cheated my way around this but I really do think there is definitely an easier way out there in the wilderness
What I did is to post a notification (using my own completely decoupled notification system) to send the created clip which is then captured by the respective playableBehaviour:

[TrackColor(0.855f, 0.8623f, 0.87f)]
[TrackClipType(typeof(MonitorTextAnimatorClip))]
[TrackBindingType(typeof(MonitorOutput))]
public class MonitorTextAnimatorTrack : TrackAsset
{
    public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
    {
        return ScriptPlayable<MonitorTextAnimatorMixerBehaviour>.Create (graph, inputCount);
    }

    protected override Playable CreatePlayable (PlayableGraph graph, GameObject go, TimelineClip clip)
    {
        var p = base.CreatePlayable (graph, go, clip);
        NotificationCenter.Post (NotificationType.ClipCreated, new object[]{ p, clip });
        return p;
    }
}
[Serializable]
public class MonitorTextAnimatorBehaviour : PlayableBehaviour
{
    private Playable playable;
    private TimelineClip clip;
    public override void OnPlayableCreate (Playable playable)
    {
        this.playable = playable;
        NotificationCenter.AddListener(OnClipCreated,NotificationType.ClipCreated);
        base.OnPlayableCreate (playable);
    }

    public override void OnPlayableDestroy (Playable playable)
    {
        NotificationCenter.RemoveListener(OnClipCreated,NotificationType.ClipCreated);
        base.OnPlayableDestroy (playable);
    }

    private void OnClipCreated(Notification note)
    {
        var data = (object[])note.data;
        var clipOwner = (Playable)data [0];
        if (clipOwner.GetHashCode() == playable.GetHashCode()) {
            clip = (TimelineClip)data [1];
            Debug.Log (clip.start + "   " + clip.end);
        }
    }
}

I know, I know, its uglier then an ugly duckling that decided to let itself go. I really hope someone comes up with the right answer (I know you’re definitely somewhere out there, go ahead, start writing that delicious answer). :p:p:p:p:p:p

You can cut out your notification system by setting the clip directly on the behaviour like this:

    protected override Playable CreatePlayable (PlayableGraph graph, GameObject go, TimelineClip clip)
    {
        ScriptPlayable<MonitorTextAnimatorBehaviour > playable = (ScriptPlayable<MonitorTextAnimatorBehaviour >) base.CreatePlayable(graph, go, clip);
        playable.GetBehaviour().clip = clip;
        return playable;
    }
1 Like

Thanks a lot, that is absolutely great!!!

Hi there,
I know that this thread is quite old now, but Unity version were you using for this?
I’m also trying to get the TimelineClip information of a clip but for some reason CreatePlayable(PlayableGraph graph, GameObject go, TimelineClip clip) is internal, not virtual in Unity 2018.1.3 so I’m not able to override it and assign the clip myself.