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 MOrlando616 · Aug 08, 2014 at 03:53 PM · animationmecanim

How can I determine when a MecAnim animation is done?

As the title suggests, I'm having trouble determining when, specifically, my turn animation is complete so that I can send my player avatar merrily on his way to the target location. I use root motion for the turns and then want my NavMeshAgent to carry out the actual movement (so I turn off RootMotion for the walks).

I've found some information online but it doesn't seem to work for me, and I'm sure it probably has to do with my tree setup, which is nutty...

Anyway, here's some code I have to try to figure out which animation is playing:

 int[] hashVals = 
         {
             Animator.StringToHash( "Base Layer.Idle" ),
             Animator.StringToHash( "Base Layer.Idle.idle" ),
 
             Animator.StringToHash( "Base Layer.Turn" ),
             Animator.StringToHash( "Base Layer.Turn.Left30" ),
             Animator.StringToHash( "Base Layer.Turn.Left30.left30" ),
             Animator.StringToHash( "Base Layer.Turn.Left45" ),
             Animator.StringToHash( "Base Layer.Turn.Left45.left45" ),
             Animator.StringToHash( "Base Layer.Turn.Left60" ),
             Animator.StringToHash( "Base Layer.Turn.Left60.left60" ),
             Animator.StringToHash( "Base Layer.Turn.Left90" ),
             Animator.StringToHash( "Base Layer.Turn.Left90.left90" ),
             Animator.StringToHash( "Base Layer.Turn.Left135" ),
             Animator.StringToHash( "Base Layer.Turn.Left135.left135" ),
             Animator.StringToHash( "Base Layer.Turn.Left180" ),
             Animator.StringToHash( "Base Layer.Turn.Left180.left180" ),
             Animator.StringToHash( "Base Layer.Turn.Right30" ),
             Animator.StringToHash( "Base Layer.Turn.Right30.right30" ),
             Animator.StringToHash( "Base Layer.Turn.Right45" ),
             Animator.StringToHash( "Base Layer.Turn.Right45.right45" ),
             Animator.StringToHash( "Base Layer.Turn.Right60" ),
             Animator.StringToHash( "Base Layer.Turn.Right60.right60" ),
             Animator.StringToHash( "Base Layer.Turn.Right90" ),
             Animator.StringToHash( "Base Layer.Turn.Right90.right90" ),
             Animator.StringToHash( "Base Layer.Turn.Right135" ),
             Animator.StringToHash( "Base Layer.Turn.Right135.right135" ),
             Animator.StringToHash( "Base Layer.Turn.Right180" ),
             Animator.StringToHash( "Base Layer.Turn.Right180.right180" ),
 
             Animator.StringToHash( "Base Layer.Move" ),
             Animator.StringToHash( "Base Layer.Move.move" ),
         };
 
         AnimatorStateInfo info = m_Animator.GetCurrentAnimatorStateInfo( 0 );
 
         string debug = "NameHash:  " + info.nameHash;
 
         for( int i = 0; i < hashVals.Length; ++i )
             debug += ( "\n" + i + ": " + hashVals[ i ] );
 
         Debug.Log( debug );

The output I get from that code is as follows:

 NameHash:  1462193319
 0: 1432961145
 1: -1431335092
 2: -1452416981
 3: 1050542541
 4: -1420186527
 5: 28664709
 6: -1191989884
 7: 1139406216
 8: -1665589909
 9: -999167673
 10: -996618635
 11: 1240697871
 12: -1193521342
 13: -630349493
 14: -1724523330
 15: 675598804
 16: 1669565844
 17: 393196444
 18: -186404374
 19: 1429415313
 20: -119688555
 21: -760530594
 22: -1907427881
 23: 764345887
 24: 2038285514
 25: -1106193573
 26: 803972494
 27: 1718862356
 28: 1520272379

The following 2 images show off the turning section of my mecanim controller. Each state (Left30, Left45, etc etc) contain a single blend tree that blends based on speed between a stationary, walking, and jogging turn.

alt text

alt text

baselayer.png (20.6 kB)
baselayer_turn.png (82.2 kB)
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
1
Best Answer

Answer by joshh · Aug 08, 2014 at 04:36 PM

I would suggest either making an animation event on the clip in the state that sends info to a function, or name all the transitions exiting the animation and look for the name of the transition when in a transition.

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 MOrlando616 · Aug 08, 2014 at 08:22 PM 0
Share

I finally learned that in order to add an animation event, you have to scrub through the animation within the preview window. Despite being convoluted, the animation events work great.

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

22 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

Related Questions

Reference clip for Additive blending animation in Mecanim 0 Answers

Setup specific frame of a sprite animation and stop the animation there 0 Answers

Can I make animations snap to a frame? 1 Answer

mecanim keep feet planted 0 Answers

Scale assets AND Mecanim animation Keyframes? 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