Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Referencing Markers from Clips

Discussion in 'Timeline' started by mrtenda, Jul 26, 2019.

  1. mrtenda


    Jun 6, 2017
    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.
  2. seant_unity


    Unity Technologies

    Aug 25, 2015
    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.

    Code (CSharp):
    2. public class TimeMarker : UnityEngine.Timeline.Marker
    3. {
    4.     void OnValidate()
    5.     {
    6.         this.hideFlags &= ~HideFlags.HideInHierarchy;
    7.     }
    8. }
    10. ....
    12. public class TimeMarkerReferenceClip : PlayableAsset
    13. {
    14.     public TimeMarker timeMarker;
    16.     public override Playable CreatePlayable(PlayableGraph graph, GameObject director)
    17.     {
    18.         if (timeMarker != null)
    19.             Debug.Log(timeMarker.time);
    20.         return Playable.Create(graph);
    21.     }
    22. }
    mrtenda likes this.
  3. mrtenda


    Jun 6, 2017
    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)