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…
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;
}
}
@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?)
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;
}
}