Referencing Markers from Clips

We are creating a custom Timeline playable that will make the Timeline conditionally skip ahead to a specific future time if a flag is set. It would be nice to be able to use a Marker to specify that future specific time, and then reference that Marker from our custom clip.

I have tried having the clip reference the Marker both using and not using ExposedReferences, but neither way seems to work, as the editor doesn’t allow me to drag the Marker into the clip and the Marker doesn’t show up when I click on the target icon to the right of the field on the clip:

Is there any possible way to reference a Marker’s time from a custom clip? I am using Unity 2019.1.2f1.

1 Like

Mostly yes.

You can’t drag the asset from the timeline itself (timeline assumes that you are trying to move the marker), but you can drag and drop the time marker asset. By default it’s a hidden subasset of the timeline, but there is a way around that by removing the hideInHierarchy flag.

After creating the timemarker you need to save the project, and the timeline will show a subasset for the time marker you added. You should be able to drag that into timeline to add the reference to the marker class.

You don’t need an exposed reference since the marker is an asset and not an Object in the scene.

public class TimeMarker : UnityEngine.Timeline.Marker
{
    void OnValidate()
    {
        this.hideFlags &= ~HideFlags.HideInHierarchy;
    }
}

....

public class TimeMarkerReferenceClip : PlayableAsset
{
    public TimeMarker timeMarker;
   
    public override Playable CreatePlayable(PlayableGraph graph, GameObject director)
    {
        if (timeMarker != null)
            Debug.Log(timeMarker.time);
        return Playable.Create(graph);
    }
}
3 Likes

Thank you so much, that worked!

(For any future readers: I actually ended up overriding OnInitialize and putting the hideflags code in there instead of OnValidate, since OnValidate wasn’t working every time)

hi, when i set this hideflags in OnInitialize, then have a error msg : “get_hideflags is not allowed to be called during serialization, call it from onenable instead. called from scriptableobject ‘markertrack’.” Can you help me, Thank you

You should be able to call it from OnEnable instead of OnInitialize. Markers are ScriptableObjects and get OnEnable called when loaded.

1 Like