- Home /
Pause mecanim animation
Is there a way to pause current mecanim animation clip, like we did with Animation.Stop() for the legacy animation system?
Answer by TonyLi · Apr 04, 2013 at 01:50 PM
Have you tried Animator.speed = 0?
Thats good, in certain situations. But it affects the overall speed. I guess there's no option to target a single clip/layer?
Depending on your needs, you could create a Pause bool that transitions to a null state when true and returns to the original state when false.
If you want to pause a layer, you could set (or damp) the layer's weight to 0.
Answer by rsodre · May 19, 2017 at 06:09 PM
animator.enabled = false;
This is a good solution for Unity 5.6+. For earlier versions, animator.enabled will reset the animator's state.
Answer by Alond · Jun 13, 2017 at 06:30 PM
If anyone still wondering, I think the best way to pause a specific animation state is to create a float parameter in the animator controller called something like "animSpeed" and assign it to the speed multiplier parameter of the animation state, then you can call animator.SetFloat ("animSpeed", 0f) to pause the animation and animator.SetFloat ("animSpeed", 1f) to resume it. Hope it helps someone. :)
How can you access a single animation within the animator?
Hello. I know it's been years but i'm interested in your idea of pausing the animation state. Can you please clarify how you assign the float parameter to the speed multiplier? Thanks, Bill
Sure In the Parameters tab of the Animator window, create a new float parameter to control the speed of a certain animation state. Then, in the inspector of this state, enable the checkbox of the Speed - $$anonymous$$ultiplier property and assign the float parameter that you just created. Then control it through script like: Animator anim = GetComponent(); anim.SetFloat("anim_spped", 0); // for pausing anim.SetFloat("anim_spped", 1); // for resu$$anonymous$$g
Answer by Varaughe · Dec 06, 2015 at 02:46 PM
//You may simply keep the animator playing from the same key time
float freezeTime;
bool freeze = false;//when freeze gets true,freeze animation !
public bool Freeze{
set{
freeze = value;
if(freeze){
freezeTime = animator.GetCurrentAnimatorStateInfo(0).normalizedTime;
}
}
}
Update(){
if(freeze){
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
animator.Play (stateInfo.nameHash, 0, freezeTime);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613093839im_/https://answers.unity.com/themes/thub/images/avi.jpg)