Animator - Stoping && Playing from Specific frames.

Hello everyone, thank you for stopping by.

Quick quesitons:

1)How could I stop an animation from playing?
I want to play a specific animation, lets say “walk”.

public void AnimateMovement(){
		_animator.Play("walk");
	}

But, is there a way to stop this same animation?

 public void StopMovement(){
    		_animator.Stop("walk");
    	}

I tried this but didn’t work, then I tried _animator.animation.Stop but there’s no animation component attached, I made the animations using an animator controller.

2)Is it possible to start an animation from any other frame other than the first?
For example

 public void StartMovement(){
    		_animator.Play("walk", _animator("walk")[2]);
    	}

**Start walk animation from frame 2?

Thank you for your time and knowledge.

1)How could I stop an animation from playing?

One way, stop the animator speed;

_animator.speed = 0f;

Second,
create the new state named by Pause.

For example, the transition conditions to Pause state:

_animator.SetTrigger("Pause");

you save to state when pause,
check off the “Write Defaults” parameter of Pause state.

2)Is it possible to start an animation from any other frame other than the first?

you can play specifying the normalized time.

for example, If you start from the middle:

_animator.Play("walk", -1, 0.5f);

Well if you want to do that in Animator then use this

Lets say you want to play the animation from the mid frame .This is how u will do it

getComponent().Play(“Animation_Name”,0,0.5f);

or

getComponent().Play(“Animation_Name”, 0 , (1/total_frames)*frame_number);

For more you can refer here

First off I’m not an expert on this but the following could be your problem. So your using the “Animator” component not the “Animation” component? That could be your problem. The Animation component you can use your code that you have above and it should work. However, if you use that for the “Animator” component that won’t work unfortunately. You will have to edit the variables that control your walk. For example if your walking your speed > 0.1f so set the speed variable to zero or above to walk or stop.
So for example:
JavaScript:

var anim : Animator;
function SetSpeed(){
    anim.SetFloat("speed", 1.3f);//Set the speed variable to 1.3f and the animator takes care of the rest.
}

C#:

public Animator anim;
void SetSpeed(){
        anim.SetFloat("speed", 1.3f);//Set the speed variable to 1.3f and the animator takes care of the rest.
    }

Hope this helps!

Thanks to everyone! Probably some one is looking for a way to find out a normalized time of the running animation.

In my case I’m using the following line to get the current normalized time of the running animation:

float_var = animator.GetCurrentAnimatorStateInfo(0).normalizedTime;

And after that I can replay the animation from the particular frame as it was mentioned above:

animator.Play("anim_name",0,float_var);

you can stop animation on any frame you want… for example you want to stop animation at the position of very first frame. just use these line of code

//stop animation .. on first frame
gameObject.GetComponent<Animator>().Rebind();

please try this above line if it not work for you . try the blow line of code
OR
//use this line to stop on very first frame which is 0.0f and the layer is 1
gameObject.GetComponent().PlayInFixedTime(“ClipName”,1,0.0f);