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
1
Question by neondrop · Apr 13, 2014 at 03:21 PM · animationmecanimrunonce

Running an animation completely before transitioning back (Mecanim)

Basically I want to run an animation once when I press a key. And no matter how long the key is pressed I want to run it once completely and then transition automatically back to idle state.

I really have tried to find a solution regarding to this, because there are many similiar questions on the web, but I couldn't find anything that explains this in detail, because I'm completely new to Unity.

         if (Input.GetKeyDown (KeyCode.E)) {
             anim.SetBool ("Kicking", true);
         }
 
         if(anim.IsInTransition(0) && anim.GetNextAnimatorStateInfo(0).nameHash == kickStateHash){
             anim.SetBool("Kicking", false);
         }

This is basically the code, the problem is that when I press 'E' it doesn't run 'Kick' all the way through but cuts it in the middle. I know why it's doing this, but don't know how to fix it.

I also tried this:

     if (Input.GetKeyDown (KeyCode.E)) {
         anim.SetBool ("Kicking", true);
     }

     if (anim.GetCurrentAnimatorStateInfo(0).nameHash == kickStateHash) {
     } else {
         anim.SetBool ("Kicking", false);}

But it doesn't work at all. (I don't get any errors but the animation isn't -visibly- playing)

I also tried with a Trigger instead of a Bool, but then again the animation only plays halfway and then transitions back to Idle.

Comment
Add comment · Show 1
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 Simon-Larsen · Apr 13, 2014 at 03:27 PM 1
Share

What is the transition back condition in your animator? Check and make sure you let the animation transition back only after the Exit Time of the animation

2 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by FerretallicA · Sep 24, 2014 at 08:52 PM

1) make sure you turn looping off for the kicking animation

alt text

2) for the transition from Kick animation to Idle (or whatever you want it to go back to), make sure you set both ExitTime to 1 and Kicking to false.

alt text

This will ensure that the animation will run once, and only once, then return to the Idle animation only when Kicking is false and the animation has completed in full.


unity1.png (3.7 kB)
unity2.png (5.3 kB)
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 neondrop · Apr 13, 2014 at 03:59 PM

Sorry guys, it seems I'm really stupid. I have the solution now. In case anyone is looking for this as well: Instead of making it complicated and trying to set a bool to false to transition back into idle, simply use exit time in the 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

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

23 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

Related Questions

Triggering an animation once in mecanim 4 Answers

[Mecanim] How To Play Animation? 1 Answer

Add more bones to skeleton - vertebraes definition...? 0 Answers

How to create a 2D rig? 1 Answer

Multiple Animation Events not firing 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