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
2
Question by RemiR · Nov 08, 2014 at 07:40 PM · animationanimatorbugdetection

Problem with Hash IDs & End of animation detection

Hello everyone,

I would like to detect the end of attack animation.

First of all, I tried to use Animation Events but they don't work (sometimes when animation was very fast the event was not triggered).

I decided to create a custom method for detect an animation changed :

    private void CheckEndOfAnimation()
     {
         var state = CharAnimator.GetCurrentAnimatorStateInfo(0);
         if (Attacking)
         {
             if (!_checkEndAnim)
             {
                 if (_currentAttackState != state.nameHash)
                 {
                     _currentAttackState = state.nameHash;
                     _checkEndAnim = true;
                 }
             }
             else
             {
                 if (_currentAttackState == state.nameHash)
                 {
                     if (state.normalizedTime >= 0.99f && !CharAnimator.IsInTransition(0))
                     {
                         if (_currentAttackTrail != null)
                         {
                             _currentAttackTrail.transform.parent = null;
                         }
                         Attacking = false;
                         _checkEndAnim = false;
                     }
                 }
                 else
                 {
                     if (_currentAttackTrail != null)
                     {
                         _currentAttackTrail.transform.parent = null;
                     }
                     Attacking = false;
                     _checkEndAnim = false;
                 }
             }
         }
         else
         {
             _currentAttackState = state.nameHash;
         }
     }



It seems to work for most cases... but sometimes "state" variable (CharAnimator.GetCurrentAnimatorStateInfo(0)) change in the middle of an animation (without reason).

For debug this problem, I would like to know what is the new animation... but i can't get the state name.

I tried to instantiate (in Start method) a dictionnary with state name and hash ids for i can't get the hash (wich is in substate system).

 // Works
 
 AnimHashes.Add(Animator.StringToHash("Base.Idle"), "Idle");
 
 
 // Doesn't work
 
         AnimHashes.Add(Animator.StringToHash("Base.RightWeakAttack2"), "RightWeakAttack2");
       AnimHashes.Add(Animator.StringToHash("Base.Attacks.WeakAttack.RightWeakAttack2"), "RightWeakAttack2_TEST");


alt text

Thanks for your help,

Best regards.

example.png (106.8 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

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by RemiR · Nov 09, 2014 at 06:41 PM

After spent the whole day to debug I found a solution :

Firstly, I found how get an hash id of animation clip (inside substate of substate animator).

Base => Attacks (substate) => WeakAttack (substate) => RightWeakAttack1 (selected animation)

I think the documentation is not complete enough and this page should be updated :

http://docs.unity3d.com/ScriptReference/Animator.StringToHash.html

You must use :

 Animator.StringToHash("WeakAttack.RightWeakAttack2")


Secondly, I forgot a condition to check the end of animation : Verify that the trigger animation boolean equals false.

I give the solution here for those who have the same problem

Best regards,

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 NoiseFloorDev · Aug 08, 2017 at 04:56 AM 0
Share

Old question, but people like me still search their way here. $$anonymous$$aybe fullPathHash didn't exist when this was asked:

If you use AnimatorStateInfo.fullPathHash ins$$anonymous$$d of AnimatorStateInfo.nameHash you don't have this problem. That's the hash of the complete path including the layer name and all parent state engines, eg. "Base.Attacks.WeakAttack.RightWeakAttack1". This way the hashes aren't ambiguous when you use the same state name in different substates, and you can use the full hash with Animator.Play as well.

avatar image
1

Answer by · Mar 04, 2016 at 03:03 PM

@RemiR here is issues for that. Vote please https://issuetracker.unity3d.com/issues/animator-animator-dot-gotostate-state-could-not-be-found and https://issuetracker.unity3d.com/issues/animator-dot-hasstate-does-not-properly-return-true-for-nested-substates
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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Bug animation transitions, or am I the bug? 0 Answers

2D Animation does not start 1 Answer

Animator problem in Create with Code. in Unit 3 1 Answer

Mecanim CrossFade transition interruption issue 3 Answers

Unity not playing Legacy animation 0 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