How Do I Get And Set References For Timeline?
I've been scanning through the docs like a mad man, but I can't figure out how to get and set references to game objects in Timeline tracks.
I want to work on some scripts that will dynamically insert references to game objects into Timeline, but I can't find what the method calls are.
I've found some functions like:
director.GetGenericBinding(o);
director.playableGraph.GetOutput(id).GetReferenceObject();
director.playableGraph.GetRootPlayable(id);
But I still can't seem to grab existing references and figure out how to set new ones. I don't really understand the difference between graphs, playables, outputs, and whatnot. Does anyone have experience with getting and setting these references in script?
WOW! I'm a bit dumb sometimes. Okay let me show you guys what it looks like all put together!
using UnityEngine.Timeline;
using UnityEngine.Playables;
public class TimelineTools : $$anonymous$$onoBehaviour
{
private int trackID;
private TimelineAsset asset;
public GameObject referenceObject;
void Start()
{
// Get the timeline asset
asset = director.playableAsset as TimelineAsset;
// Get track asset
var track = asset.GetOutputTrack(trackID);
// Get the current bound object to the track
Debug.Log(director.GetGenericBinding(track));
// Change the bound object
director.SetGenericBinding(track, referenceObject);
}
}
Answer by seant_unity · Feb 11, 2020 at 12:43 PM
Use director.SetGenericBinding(Track, Object);. The tracks can be obtained from TimelineAsset.GetOutputTracks().
The Object will depend on the type of the track, so either GameObject for an ActivationTrack, Animator for an AnimationTrack, or CinemachineBrain for a CinemachineTrack.
Thank you!
I think what screwed me up is that I wasn't importing using UnityEngine.Timeline;
, so I got really confused. It all makes sense now haha
Super useful when you are working with timelines and prefabs