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
3
Question by stralberg · Sep 04, 2013 at 09:07 PM · animatorendoneshot

End of animation clip using Animator (Mecanim)

I'm using Mecanim Aninator for my walks, run etc and all that works nicely driven from a C# script. Sometimes I need to start a one-shot animation and that also is not problem using Exit Time. However I need to know when the one-shot has ended from my script.

Any ideas how to do that?

Comment
Add comment · Show 2
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 AndyMartin458 · Sep 04, 2013 at 11:45 PM 0
Share

I tried to figure out the same thing but was unsuccessful. Hopefully someone else wants this as well.

avatar image TomPo · Nov 24, 2017 at 08:59 PM 0
Share

I'm using something like this

 private IEnumerator BackToIdle() {
    //start your new animation here
     yield return null; //wait 1 frame so nextState loaded
     float time = anim.GetNextAnimatorStateInfo(0).length;
     yield return new WaitForSeconds(time); //wait for animation to finish
     //do what you want like back to normal speed
     anim.speed = 1;
     //start idle animation
     yield break;
 }

You have to uncheck "have exit time" in back transition

4 Replies

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

Answer by AndyMartin458 · Sep 05, 2013 at 12:33 AM

The last answer in this page seems to answer the question pretty well. http://answers.unity3d.com/questions/362629/how-can-i-check-if-an-animation-is-being-played-or.html You essentially need to poll the animation state until it is not the expected one. Mixamo also created a package that is free and can be hooked to different parts of the animation.

My suggestion is to create a system that will call that event whenever this situation is not true. I can probably do this if you poke me. I'm just going to make an animation event system that does this for you easily.

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 stralberg · Sep 05, 2013 at 06:26 AM 0
Share

Thanks. GetCurrentAnimatorStateInfo solved my problem nicely :D

avatar image AndyMartin458 stralberg · Sep 05, 2013 at 04:53 PM 0
Share

I didn't downvote this, but you need to leave this as a comment on my post, and if you like the answer, click the checkmark to mark it as the answer.

avatar image
2

Answer by yonixw · Apr 24, 2015 at 03:53 AM

I had the same problem detecting the end of the clip. I prefer using Animator\Animation events.

It's explained in the API documentation: http://docs.unity3d.com/Manual/AnimationEventsOnImportedClips.html http://docs.unity3d.com/Manual/animeditor-AnimationEvents.html

Comment
Add comment · Show 1 · 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 raptorkwok · May 13, 2015 at 08:46 AM 0
Share

Animation Events are really useful in this case.

avatar image
1

Answer by Jeet_9811 · Jun 03, 2014 at 11:27 AM

 if(stateInfo.IsName("Hat"))
     {
         if(stateInfo.normalizedTime >= 0.99f)
         {
             //b_hat = false;
             _animator.SetBool("hat", false);
         }
     }

But this is playing the animation again sometimes.

Comment
Add comment · Show 1 · 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 abdulthegamer · Jun 11, 2014 at 12:34 PM 0
Share

Have you written correct boolean variable name...? Or are you trying to stop the existing animation before playing the new one..?

Think of it.. You can figure it out easily...

avatar image
0

Answer by DantaliaN · Mar 19, 2016 at 05:04 PM

In animator set trigger "IsDestroy" and make connections between "Breake" and "Destroy" animation throw change trigger. "Destroy" animation is empty, Just for triggering

  IEnumerator PlayBreak()
     {
         animator.SetTrigger("IsDestroy"); 
         animator.Play("Break"); 
 
         while (animator.GetBool("IsDestroy"))
         {
             yield return null;
         }
 
         GameObject.Destroy(this.gameObject);
     }
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

25 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

Related Questions

2D Animation does not start 1 Answer

Is it possible to switch AvatarMask at runtime? 0 Answers

Animator unable to properly transition between Animation Clips 1 Answer

Why is my Animation not Retargeting Correctly? 1 Answer

Blending between frames in the same animation (fake stop motion) 2 Answers


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