Animation track: swapping Animator at runtime

Hi everyone!

I have a timeline with an Animation track and one animation clip. I have two different characters (A and B) with two incompatible generic rigs and character B has an animator override for its custom animations.
I am constrained to use generic rigs, I can't use humanoids.

I have authored the timeline with character A and I need the timeline to work with both characters (depending on which one activates it).
I have tried assigning character B's animator to the animation track with SetGenericBinding and I can see that the timeline is playing the correct clip from the animator override, but it seems that it's still using the rig from character A, so the animation is horribly broken.

Is there a way to make sure the animation will play with the correct rig?

Thanks.

I got it working: what I did is setting the binding with the animator, then scan through all the TimelineClips in the AnimationTrack and change the asset clip.

director.SetGenericBinding(binding.sourceObject, nextUser.Animator);

if (!nextUser.Animator.isHuman) {
   // Remap the animations
   AnimatorOverrideController aOverride = nextUser.Animator.runtimeAnimatorController as AnimatorOverrideController;
   if (aOverride != null) {
      AnimationTrack track = binding.sourceObject as AnimationTrack;
      foreach (TimelineClip clip in track.GetClips()) {
         AnimationClip remapClip = aOverride[clip.displayName];
         (clip.asset as AnimationPlayableAsset).clip = remapClip;
      }
   }
}
2 Likes