How do "I add my mainCamera to my Timeline at runtime"/"user SetGenericBinding()"?
Hi.
I have a timeline in the 7th scene, and my camera is in the 1st scene with dontDestroyOnLoad in it, so I can't drag my camera in the editor to my timeline. So I duplicated my main camera e put it in the 7th scene just to make the animation, and then I deleted.
Now I want to asign my camera in my timeline (bindings) at runtime but I don't know how... I've been searching around but no luck. I see that there's a function called SetGenericBingind but I know how to get the source object that is asking.
Please, can anyone help me with this?
Answer by seant_unity · Oct 03, 2018 at 03:21 PM
PlayableDirector.SetGenericBinding( key, value) is the correct way to dynamically bind. The key is the track in the timeline you want to bind to, and the value is the animator (for Animation Tracks).
One method to find the track is to search by name. For example:
public static void Bind(PlayableDirector director, string trackName, Animator animator)
{
var timeline = director.playableAsset as TimelineAsset;
foreach (var track in timeline.GetOutputTracks())
{
if (track.name == trackName)
{
director.SetGenericBinding(track, animator);
break;
}
}
}
Make sure to call this before playing the timeline, or the binding may not take effect.
Oh man, thank you so much, that was exactly what I was looking for.
Feeling like a director myself already \o/
Your answer
![](https://koobas.hobune.stream/wayback/20220612175712im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity 2019 Step Key Animation Issue from Maya 0 Answers
Why can't a Timeline key frame contain zero Position values? 2 Answers
Recording animation into the timeline (and playing it back) at runtime 1 Answer
Can't animate Text Color (Timeline) 0 Answers
Animator parameter on Timeline Keyframe 0 Answers