How Do I Change the Animator Component Tied to a Timeline Animation Track During Runtime?

The idea is to make it so that in the editor, I can use a Timeline Asset to preview sequences without having to worry about what specific Animator components will be used during runtime. Depending on what’s happening in game, it won’t always be the same model(s) going through the animations. That’s why I want to use C# to swap things in and out as appropriate.

Thing is… How do I do that?

I know that creating a custom PlayableBehaviour is part of it, but not much else. I’d appreciate help with this.

You have to rebind the Animator at runtime.

public static void BindObject(this PlayableDirector playableDirector, string trackName, GameObject toBind)
    var optTracks = OptTracks(playableDirector);
    if (optTracks.None()) return;
    foreach (var outputTrack in optTracks.Single())
        // IndusLogger.Debug($"[UnityExtensionUtils.BindObject()]","timeline {} track {outputTrack} requested {trackName}");
        if ( != trackName) continue;

        var type = outputTrack.outputs
            .Select(b => b.outputTargetType)

        Object toBindObject = toBind;
        if (type == typeof(GameObject))
            //We're good
        else if (type == typeof(Animator))
            toBindObject = toBind.GetComponent<Animator>();
        }//TODO anything else if needed
        else if (type == typeof(CinemachineBrain))
            toBindObject = toBind.GetComponent<CinemachineBrain>();

        playableDirector.SetGenericBinding(outputTrack, toBindObject);