- Home /
Is there a way to replace animation clip in AnimatorController in editor ?
Hi there
According to such as this topic in doc :
https://docs.unity3d.com/ScriptReference/Animations.AnimatorController.html
https://docs.unity3d.com/ScriptReference/Animations.AnimatorState.html
https://docs.unity3d.com/ScriptReference/Motion.html
I can't find any way to get or set animation clip in class which named AnimatorState.
In other words , Is the only way to replace clip in controller that used Override Animator Controller ?
Thanks
Answer by Grish_tad · Jan 05, 2018 at 09:54 AM
HI @HahnSC . If you want to change animations in animatorState during runtime you need to use Animator Override Controller. Here is a simple code with changing animation in animator states
Animator anim = gameObject.GetConponent<Animator>();
AnimatorOverrideController aoc = new AnimatorOverrideController(anim.runtimeAnimatorController);
var anims = new List<KeyValuePair<AnimationClip, AnimationClip>>();
anims.Add(new KeyValuePair<AnimationClip, AnimationClip>(AnimationClipInAnimator, NewAnimationClip)));
aoc.ApplyOverrides(anims);
anim.runtimeAnimatorController = aoc;
Hi Grish_tad , Thank you for answer.
Sry, I wish i could modify AnimatorController and replace AnimatorState.$$anonymous$$otion by code.
You can do that in editor time, not in realtime.
Your answer
![](https://koobas.hobune.stream/wayback/20220612145854im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do you control where your animation starts? 1 Answer
Unity 2D : Can you change a 2D animation clip's sprites at runtime? 8 Answers
Dynamically create states and transition using Animator Controller 1 Answer
Animator Override Controller changed at runtime doesn't always play the animations correctly 1 Answer
Hiding non-public functions from Animation Event Window? 0 Answers