Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Animation track: swapping Animator at runtime

Discussion in 'Timeline' started by OG_Igor, Oct 17, 2022.

  1. OG_Igor

    OG_Igor

    Joined:
    Jul 20, 2022
    Posts:
    4
    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.
     
  2. OG_Igor

    OG_Igor

    Joined:
    Jul 20, 2022
    Posts:
    4
    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.

    Code (CSharp):
    1.  
    2. director.SetGenericBinding(binding.sourceObject, nextUser.Animator);
    3.  
    4. if (!nextUser.Animator.isHuman) {
    5.    // Remap the animations
    6.    AnimatorOverrideController aOverride = nextUser.Animator.runtimeAnimatorController as AnimatorOverrideController;
    7.    if (aOverride != null) {
    8.       AnimationTrack track = binding.sourceObject as AnimationTrack;
    9.       foreach (TimelineClip clip in track.GetClips()) {
    10.          AnimationClip remapClip = aOverride[clip.displayName];
    11.          (clip.asset as AnimationPlayableAsset).clip = remapClip;
    12.       }
    13.    }
    14. }
    15.  
     
    Yuchen_Chang and akent99 like this.