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?

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.