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 ICEYHOTSTUNTA · Dec 14, 2012 at 07:37 AM · animationanimatormecanimstate

How to generate Mecanim Sub-state namehash?

 To figure out what animation state an animator is in I can do this:
         
     AnimatorStateInfo currentState= animator.GetCurrentAnimatorStateInfo(0);
     if (currentState.nameHash == Animator.StringToHash("Base Layer.state"))
     {
          // I'm in "state"
     }
         
 So if I am in a sub-state I figured this would work:
         
     AnimatorStateInfo currentState = animator.GetCurrentAnimatorStateInfo(0);
     if (currentState.nameHash == Animator.StringToHash("Base Layer.parentState.subState"))
     {
          // I'm in "subState"
     }
     
 But it doesn't... What string is used to generate the name has of sub-states?
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

6 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by bushdiver · Mar 29, 2013 at 12:17 AM

This was a pain.. The sub-state becomes the layer name, I don't know if this is a bug or was intended.

In the example above to get the sub-state.state hashName:

 AnimatorStateInfo currentState = animator.GetCurrentAnimatorStateInfo(0);
 if (currentState.nameHash == Animator.StringToHash("parentState.subState"))
 {
      // I'm in "subState"
 }


Animator.StringToHash("parentState.subState") rather than Animator.StringToHash("Base Layer.parentState.subState")

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 dylanfries · Dec 23, 2013 at 12:32 AM 0
Share

What about nested, can you just keep going? "Base.state.substate.subsubstate"

avatar image Pulov · Apr 17, 2015 at 03:22 PM 0
Share

Does not work for me... aaah unity... Neither did the modifications posted after.

avatar image
0

Answer by DrEvil · Dec 16, 2012 at 06:07 PM

Base.State.AnimName should work. Looks like you are using "Base Layer.etc rather than just "Base.etc"

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 Kwaung · Feb 22, 2013 at 04:20 PM

I use Animator.StringToHash("parentState.subState") seem to work for me. (Yes no "Base Layer".) But I didn't try with state that have more then one layers yet.

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 stealann · Dec 22, 2013 at 04:39 PM

@bushdiver Does anyone tested Unity 4.3.1? I am using Unity4.3.1 and seems it doesn't works anymore x_x. I did the test of getting the sub-state of Locomotion in the tutorial project of Mecanim:

 Start(){
     static int runState = Animator.StringToHash("Base.Locomotion.Runs");
 }
 FixUpdate(){
         
         currentBaseState = anim.GetCurrentAnimatorStateInfo(0);    // set our currentState variable to the current state of the Base Layer (0) of animation
            
         if (currentBaseState.nameHash == runState){
             Debug.Log ("I am Running!");
         }
 }

I also tried ("parent-State.Sub-state") and it doesn't work either...

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 tanoshimi · Dec 22, 2013 at 07:33 PM

@stealann - please don't ask additional questions as answers - start a new thread. The reason your code doesn't work is because Locomotion in the Mecanim tutorial is not a substate - it's a blend tree. Therefore the animator is never in the "runs" state - that's just a motion field that is blended as part of the locomotion state. This code works fine:

 runState = anim.StringToHash("Base Layer.Locomotion");
 var currentBaseState = anim.GetCurrentAnimatorStateInfo(0);
 if (currentBaseState.nameHash == runState){
     Debug.Log ("I am Running!");
 }
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 stealann · Dec 23, 2013 at 05:06 AM 0
Share

Thanks for answering. I will start a new thread for this. As you said, I misunderstood the name of the animation clips in BlendTrees as Sub-status. What I actually wannna access is the blending situation of the blendtree.

  • 1
  • 2
  • ›

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

16 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

Related Questions

Is it possible to make empty, passing state in mecanim? 3 Answers

Not able to use a Vector as a condition in Mecanim? 2 Answers

How do I make the transition between two states in the "Animator" happen instantly? 3 Answers

How to get fileID information so i can just edit Mecanim Animator through script? 2 Answers

Can't set animator bool to True 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