Last active
January 22, 2023 20:57
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} | |
} |
Thanks and good catch, makes sense.
@ciro-unity I owe you a good beer for that example, thank you!
Happy to hear @KongoPL :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
might as well add a break; after line 18, saves iterating through all the tracks even after you've got the one you want