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 castor · Apr 23, 2014 at 08:18 PM · mecanimstates

Mecanim - Detect End of state properly

So I need to know exactly when a state as ended to trigger another action.

So I have a state called "KickInHead" that transitions from Idle and once finished goes back to Idle.

 var kickInHeadState : int = Animator.StringToHash("Base Layer.KickInHead");
 var idleState : int = Animator.StringToHash("Base Layer.Idle");
 

It's all setup correctly and works fine. Then I start the animation with a trigger and define a character state that I can use to update him once the animation has completed:

 animController.anim.SetTrigger("isKickingHead");
 currentState = PlayerStates.BeatingUpActor;

Then, while the actor is in this new state I'm running this:

 if (animController.currentBaseState.nameHash != animController.kickInHeadState){
     currentState = PlayerStates.Idle;
 }

But what I noticed was that it immediately goes to 'PlayerStates.Idle, like the new state hasn't started yet. I assumed the issue would be the transition, that in theory its not yet on the new 'kickInHeadState' but actually transitioning which makes sense. So I added this:

 if (!animController.anim.IsInTransition(0) && animController.currentBaseState.nameHash != animController.kickInHeadState){
     currentState = PlayerStates.Idle;
 }

And it still doesn't work...he still believes I'm in Idle...so the only way I can do it is by writing and saying : leave this state IF back to Idle and Not in transition...

 if (!animController.anim.IsInTransition(0) && animController.currentBaseState.nameHash == animController.idleState){
     currentState = PlayerStates.Idle;
 }

And now it works fine...but it feels very messy to me, its like states are overlapping. I assumed that 'GetCurrentAnimatorStateInfo' would give you only ONE state but it seems like the state machine actually has overlapping states on the same layer?

Any help would be very appreciated!

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
0
Best Answer

Answer by castor · Jul 18, 2014 at 06:14 PM

Just realized I asked the same question yesterday but much more articulate :) Also got a great reply to it.

You can read about it here: http://forum.unity3d.com/threads/mecanim-going-from-statea-stateb-statea-knowing-when-second-statea-has-started.257635/

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 harshaxnim · Sep 13, 2018 at 09:08 PM 0
Share

you forgot that you had asked the question just the day after asking? o_0

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

21 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

Related Questions

Mecanim add state dynamically 0 Answers

Accessing a Mecanim state through scripting, then changing the associated clip--Can it be done? 2 Answers

yield while animation plays in mecanim 0 Answers

is it possible to read states / transitions from mecanim in runtime ? 1 Answer

saving class array states 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