- Home /
 
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.


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.
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