Skip to content

Instantly share code, notes, and snippets.

@ciro-unity
Last active January 22, 2023 20:57
Show Gist options
  • Save ciro-unity/fa6ea64635c1d473b9dae64ac1853a92 to your computer and use it in GitHub Desktop.
Save ciro-unity/fa6ea64635c1d473b9dae64ac1853a92 to your computer and use it in GitHub Desktop.
A script that provides a simple example of how to dynamically assign the bound object of a track in Unity's Timeline. In this case, an Animator is assigned to an Animation track as soon as the execution starts.
using System.Collections;
using UnityEngine;
using UnityEngine.Playables;
public class TimelineBinder : MonoBehaviour
{
public PlayableDirector playableDirector; //the component which references the Timeline we want to target
public Animator objectToBind; //bound object is an Animator because we are targeting an Animation track
public string trackName;
private void Start()
{
//The "outputs" in this case are the tracks of the PlayableAsset
foreach (var playableAssetOutput in playableDirector.playableAsset.outputs)
{
if (playableAssetOutput.streamName == trackName)
{
playableDirector.SetGenericBinding(playableAssetOutput.sourceObject, objectToBind);
break;
}
}
}
}
@ciro-unity
Copy link
Author

Happy to hear @KongoPL :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment