Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by drodrii · Dec 15, 2014 at 04:25 PM · animation2dgameobjectspriteanimator

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Noob_Vulcan · Sep 18, 2015 at 06:45 AM

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 http://www.unityrealm.com/play-animation-from-frame-unity-5-animator/

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
3

Answer by maximilianahead · Mar 27, 2015 at 01:24 AM

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);

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by wesleywh · Dec 15, 2014 at 05:49 PM

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!

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image drodrii · Dec 15, 2014 at 07:19 PM 0
Share

@wesleywh

Thank you for your time. I Forgot to mention that I was using "Animator Controller". Now, i tried to do this with "Animation" ins$$anonymous$$d but when I try to do Play("walk"); nothing is happening, even though I created the animation on the 'Animation' tab and just did "create new clip" and attached it to the component...

avatar image wesleywh · Dec 15, 2014 at 07:32 PM 0
Share

For the "Animation" component the animations will only play on that character if those animations were built specifically for that character. If you are trying to use a universal animation, like walk on both character A and character B, it won't play.

However, since you are using an "Animator" component that shouldn't be a problem and you should be able to play that animation on any character. Then next thing to check is to make sure that the variable that is deciding what state to play is being initialized correctly. Like the example above you can't just call "Walk" you have to call the variable that will tell the character to go to the Walk state.

Hopefully all of that makes sense.

avatar image
0

Answer by Feelnside · Jan 04, 2018 at 05:11 PM

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);
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by samra2494 · Mar 07, 2019 at 05:55 AM

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);

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

32 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2D Animation does not start 1 Answer

Multiple Animation Controllers 1 Answer

How to make not smooth animation? 0 Answers

Best Way - Animation - Multiple GameObjects. 0 Answers

Object not moving after changing animator parameter 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges