jumping to specific points on Timeline

I have searched and searched, but this still evades me…

I have a master timeline and have set signals to pause at certain points where a player gets to make a choice and jump to different points in the timeline.

I cannot figure out how to jump to specific points in the timeline itself… I thought this would be achievable with markers, but it seems more difficult than I thought…

Any help is appreciated!

~ be

It requires some scripting, and depends on your timeline.

You can get access to the markers from the timeline asset. (playableDirector.playableAsset as TimelineAsset). From there, you need to know which track your markers are on.

If they are placed in the header area, you can get that using timelineAsset.markerTrack. Then the markers (signals, or other types of markers) can be accessed using trackAsset.GetMarkers(), and the time accessed from the iMarker.time property.

For example, to set the playable director to the first marker on the marker track.

         var timelineAsset = playableDirector.playableAsset as TimelineAsset;
            var markers = timelineAsset.markerTrack.GetMarkers().ToArray();
            playableDirector.Play();
            playableDirector.time = markers[0].time;

@seant_unity
Thank you for the quick response Sean!

I am trying to put this on a game Obj but getting errors :

Assets/_Scripts/timelineMarker.cs(25,66): error CS1061: ‘IEnumerable’ does not contain a definition for ‘ToArray’ and no accessible extension method ‘ToArray’ accepting a first argument of type ‘IEnumerable’ could be found (are you missing a using directive or an assembly reference?)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;


public class timelineMarker : MonoBehaviour
{

    private PlayableDirector playableDirector;
    //public GameObject controlPanel;


    public int markerNum;
    // Start is called before the first frame update
    void Start()
    {
        playableDirector = GetComponent<PlayableDirector>();
    }

    void OnMouseUp()
    {
           var timelineAsset = playableDirector.playableAsset as TimelineAsset;
            var markers = timelineAsset.markerTrack.GetMarkers().ToArray();
            playableDirector.Play();
            playableDirector.time = markers[markerNum].time;
    }
}

Thanks!
~be

@seant_unity
Hello hello
Thanks! What assembly am I missing? I keep getting this error in your script:

Assets/_Scripts/timelineMarker.cs(25,66): error CS1061: ‘IEnumerable’ does not contain a definition for ‘ToArray’ and no accessible extension method ‘ToArray’ accepting a first argument of type ‘IEnumerable’ could be found (are you missing a using directive or an assembly reference?)

using System.Linq.

The ToArray() call is from the Linq library. It turns a IEnumerable into a C# array.

1 Like

@seant_unity

THANK YOU !

For all those checking this threat out, This is a Great way to JUMP to different "Markers" / in a Master timeline…
For example, you have a menu where you press buttons that will take you to different places on your timeline…
(NOTE: the Marker # is not necessarily sequentially next marker … Marker # may have to do with the order in which they are created … )

working code below, please mod & make more functional & post
Thanks again @seant_unity
~be

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
using System.Linq;




public class timelineMarker : MonoBehaviour

{
    // This is to assign ANOTHER timeline (not just to one on this Game Object)
    // b/c This game object is a trigger - someting you mouse up or gaze @ -
    //  that will take you to a specific "Marker"
    // NOTE: the Marker # is not necessarily sequential... Marker # may have to do with the order in which they are created
    public PlayableDirector playableDirector;
    // The # of the Marker you want to go to
    public int markerNum;
  
    void Start()
    {
        // THIS WOULD GRAB THE TIMELINE ON THIS OBJECT but I rather call a MASTER timeline!
       // playableDirector = GetComponent<PlayableDirector>();
    }

    void OnMouseUp()
    {
           
            var timelineAsset = playableDirector.playableAsset as TimelineAsset;
            var markers = timelineAsset.markerTrack.GetMarkers().ToArray();
            playableDirector.Play();
            playableDirector.time = markers[markerNum].time;
           
    }
}
3 Likes

Is there any way to grab the markers in the order they appear on the marker track and not in the order they were created?

1 Like

Can sort with time using System.Linq

var markers = timelineAsset.markerTrack.GetMarkers().OrderBy((marker) => marker.time).ToArray();
3 Likes

Oh hell yes

1 Like

I have a custom ‘AnnotationMarker’ with a title property. Any idea how I can grab the marker with a title? I tried this:

AnnotationMarker marker = timelineAsset.markerTrack.GetMarkers().First((AnnotationMarker marker) => marker.title.Contains('foo'));

But it doesn’t recognise ‘First’ on IEnumerator. I think it is the cast though.