How to change animation clips of an animator state at runtime? Is there a way?

So I have 11 unique characters which are playable, as well as can be bots in VS CPU mode! I have 2 characters while others are still in production. I’m using mechanim for animation transitions. I want all of them to use a single animator.

Can I change the animation clips in an animator state at runtime? Because I still need to create animation clips for each character individually (which is fine), but I don’t want to create animator for each of them again! I want to use a sinlgle animator!

You can change animation clips in animators at runtime using a class called RuntimeAnimatorController.

How I used it: I have GO with an animator, it only has 1 animation but I want to swap the clip at runtime. (I have lots of very similar animations in structure and timing, just like different sprites, and I don’t feel like making dozens of extremely similar animators just because the sprites change)

This script changes ALL animations in the animator into the animation clip specified in the inspector. You can change multiple animations individually by checking their name in the foreach loop or something.

// Animator animator (get component blablabla)
// AnimationClip anim (field in inspector)

if(anim)
{
            AnimatorOverrideController aoc = new AnimatorOverrideController(animator.runtimeAnimatorController);
            var anims = new List<KeyValuePair<AnimationClip, AnimationClip>>();
            foreach (var a in aoc.animationClips)
                anims.Add(new KeyValuePair<AnimationClip, AnimationClip>(a, anim));
            aoc.ApplyOverrides(anims);
            animator.runtimeAnimatorController = aoc;
}

Original idea thread, apparently there are no other way to change clip yet:
https://forum.unity3d.com/threads/change-animation-controller-state-motion-clip-at-runtime-in-unity-5.345142/#post-2291758

Instead of specifying override clips in code, you can use the AnimatorOverrideController asset.

The AnimatorOverrideController Manual page describes how to setup an AnimatorOverrideController asset.

You can swap to it in code with:

public AnimatorOverrideController CharacterAnimator;

// Call this function from somewhere.
void SwapToOverride()
{
	GetComponent<Animator>().runtimeAnimatorController = CharacterAnimator;
}

I believe this is the first method AnimatorOverrideController ScriptReference refers to when it says:

1 . Create an Animator Override Controller in the Editor.

@dakshehs1010 Yes it is possible if you are using animator or animation component for your character. Put multiple animations in ANIMATOR window. You need to set the transition states from one animation to other animation in animator window including the default state. Set the transition conditions that could be of bool, int or string type. Use those transition conditions in your script to change the animations on runtime. e.g
Public Animator anim;
anim.setBool(“YourAnimationName”, true/false);

Thanks @Adeel1 for responding, yes I’ve already done that. The problem is something else. My bad I guess. I couldn’t explain my problem more elaborately.

The problem is, I want to change the clips stored in the states of the animator at run-time so that I don’t have to make new animators for each and every character. I want to use just one animator across all characters, which is not possible unless the animation clip in all the states of animator is changed every time the character is changed!

I know its old question, but I was looking for the same.
I found this tutorial, It seems will work


My solution : https://github.com/Voidstack/unity.utils/blob/main/AnimEmoteSelector.cs