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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by developer_arni · Dec 14, 2014 at 12:32 PM · animationanimatorblend tree

How to get the current motion on Blend tree

I have created an Animator in Unity for my character. For now it is very simple, as I am still learning the basics of animations and blend trees.

However, I have run into an issue when I converted my three walk states into a blend tree. Now I do not know how to differentiate between which motion is playing, to be able to perform some certain logic based on which animation is playing.

My current Animator looks like this:

alt text alt text

I have no problem figuring out if the character is in the idle1 state or WalkTree state by doing the following:

 animator.GetCurrentAnimatorStateInfo(0).nameHash == Animator.StringToHash("Base Layer.idle1");
 animator.GetCurrentAnimatorStateInfo(0).nameHash == Animator.StringToHash("Base Layer.WalkTree");

But how do I figure out whether it is the walk1left, walk1 or walk1right motion that is playing? Or which one is the dominating one? (Might be a more precise question.)

As animator.GetCurrentAnimatorStateInfo(0).nameHash returns the same value, no matter what motion is playing when inside the WalkTree, I cannot use the same methods as shown above anymore.

Any help is much appreciated, thanks!

baselayer.png (25.8 kB)
walktree.png (36.3 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
2
Best Answer

Answer by Mmmpies · Dec 14, 2014 at 12:36 PM

Blends do just that, blend or combine the animations so all you can get is the value of direction and base whatever you're doing on that.

Should add:

 float curDirection = anim.GetFloat("Direction");
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 developer_arni · Dec 14, 2014 at 01:18 PM 0
Share

Al right, thanks man, for the quick responds. I think I need to re-evaluate my grand animator design and logic, as I now understand Blend trees a little bit better.

avatar image Mmmpies · Dec 14, 2014 at 01:43 PM 0
Share

You're welcome. And thanks for the comment.

Really your script should be driving what the Animator is doing but it's still acceptable to get a value from the animator.

e.g. if you press to go left then SetFloat with the Direction to increase/decrease but lets say a swim$$anonymous$$g script has detected you've run into water and just gone below the level where you have to start swim$$anonymous$$g.

That swim$$anonymous$$g script sets a bool in the Animator isSwim$$anonymous$$g = true.

Your motion script checks if the Animtion bool isSwim$$anonymous$$g is true, it is. The animation speed and direction should be high so it applies the right swim$$anonymous$$g animation based on those but as swim$$anonymous$$g is different we need to get the speed float to know what force to apply to move the player.

Well that got a bit out of hand! Basically most of the time your script will be going hey Animatior do this, but you will need to go ask it what its current values are at some points.

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

27 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 avatar image avatar image avatar image avatar image

Related Questions

2D: initial sprite idle animation playing too fast upon game initiation until I input movement keys? 1 Answer

Dynamic thresholds runtime C# 1 Answer

Sebastian Lague Character Creation Tutorial animations not being triggered 0 Answers

Blend Tree Animation Problem 1 Answer

Blending animations for a bow with differing charges 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