• 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
6
Question by Superrodan · Feb 03, 2015 at 10:39 PM · animationanimatorloop

How can I reset a non-looping animation?

Hi there,

I know this is probably a super simple question to answer but I'm close to the functionality I am looking for and can't find the solution I am looking for.

I have created a very simple animation called Roll that rolls a die. I also have a button. I have it so that when you press the button it calls: Animator.Play("Roll")

The first time I tested this, the button worked. It started the roll animation. My problem was the roll animation continued to loop forever. I wanted it to only loop once, and after a google search I found that I needed to uncheck "Loop Time" on my animation. I did that and when I pressed the button it played the animation only once and then stopped in the final frame just like I expected, which was awesome.

The only problem is that after the animation stops the first time I cannot get it to play again by pressing the button again... It just sits at its final frame forever, basically. Is there some sort of reset command I need to call to play the animation again?

Thanks!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
33
Best Answer

Answer by Superrodan · Feb 03, 2015 at 11:50 PM

Ok, after finally figuring out what to search for I found an answer here:

http://answers.unity3d.com/questions/623878/how-to-restart-mecanim-state-animation-or-play-it.html

What I needed to do was create a script with a reference to the animator that called:

myAnimator.Play("Roll", -1, 0f);

This lets me press the button as many times as I want to restart the animation. I hope this helps someone else!

Comment
Add comment · Show 9 · 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 CarpetShampooer · May 07, 2015 at 02:44 PM 0
Share

Thank you, your post helped me very quickly. Just wanted to add that if you want to reset the animation on a sprite that only has one animation (like I did), just fill in the first parameter with the sprite's name.

Thanks again, I thought this would take ages to figure out.

avatar image sergiomartin · May 11, 2017 at 01:24 PM 0
Share

Thank you so much! Your post has helped me a lot. I was searching a way to reset some animations and I didn't find until I saw your post.

avatar image TUTOCF · May 12, 2017 at 08:02 PM 0
Share

Thanks you helped me a lot!

avatar image vishalpvr · Jul 21, 2017 at 12:14 PM 0
Share

Thank You ..

Your post sort out my issue....

avatar image marcinrycu · Jan 24 at 07:14 PM 1
Share

6 years later and it's still helping ! Thanks !

Show more comments

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

29 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

Related Questions

Can't play animation after setting GameObject to inactive and back to active again 4 Answers

Loop Time through Script 2D 4.3 1 Answer

Animation Loop 2 Answers

Animation keeps playing even with "loop" deactivated. 1 Answer

Loop Animation 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges