- Home /
Unity override animator stops animation on second layer
I have an animator with two layers, the second layer has an avatar mask for the upper half of the body.
https://i.stack.imgur.com/PClNJ.png
My goal is to be able to change animations for the lower and upper body at runtime and have them playing independently.
To change animations I use animator override controller: RuntimeAnimatorController myController = Anim.runtimeAnimatorController;
AnimatorOverrideController myOverrideController = myController as AnimatorOverrideController;
if(myOverrideController != null)
myController = myOverrideController.runtimeAnimatorController;
AnimatorOverrideController animatorOverride = new AnimatorOverrideController();
animatorOverride.runtimeAnimatorController = myController;
var clipOverrides = new AnimationClipOverrides(animatorOverride.overridesCount);
if(bodyPart == AnimationBodyPart.LowerBody)
animatorOverride[_currentLowerBodyClipName] = clip;
else if(bodyPart == AnimationBodyPart.UpperBody)
animatorOverride[_currentUpperBodyClipName] = clip;
animatorOverride.ApplyOverrides(clipOverrides);
Anim.runtimeAnimatorController = animatorOverride;
if(bodyPart == AnimationBodyPart.LowerBody)
Anim.SetTrigger(_startAnimLowerBody);
if(bodyPart == AnimationBodyPart.UpperBody)
Anim.SetTrigger(_startAnimUpperBody);
It works fine when changing the animation on one layer. But when I have the changed animation playing in one layer and I change the clip in another layer it stopes the animation in the first layer (they are supposed to be combined). Animator shows that both animations are running, but only the latter animation clip is actually playing.
Comment