Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Eluem · Dec 16, 2015 at 03:53 PM · mecanimanimator controllerstate-machine

Animator Sub State Machine Exit Node Issue

Issue:

I want to have some code run whenever a sub-statemachine is exited, this should be easy using a sub-statemachine behavior. However, if I use the exit node on my substate machine, the entry node on the parent state machine is ignored and it jumps directly to the default state. This is an issue for me because I have important decisions coming from the entry node of the parent.

If I want the parent entry node to activate i need to use the (Up) node, but then it doesn't trigger the OnStateMachineExit method.

Potential Work Arounds:

1) I can create a new default state in the parent state machine and duplicate all my entry node logic there. The issue is that if I use a placeholder state to make the decisions, a frame is wasted processing this node. If you make the decisions on the entry node, the decisions happen instantly, this is a far cleaner and more responsive solution than having a place holder node.

2) I can put a StateMachineBehavior on the parent state machine and put the logic on the OnStateMachineEnter method. Then I can add a parameter to the animator and use that to determine whether or not to run the code when entering the parent state machine... but this is kind of a silly cludge.

Help...

Does anyone have any advice? Is this really the intended behavior? I don't understand why exiting a sub-statemachine isn't treated similar to entering the parent behavior.

At the very least, I think they should add a new event for OnStateMachineTransitionUp.... or OnStateMachineTransitionExit or something that triggers whenever the statemachine is left for any reason...

Comment
Add comment · Show 4
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 Baste · Dec 16, 2015 at 05:14 PM 2
Share

I've complained about the behaviour of State$$anonymous$$achineEnter/Exit before, to no avail. $$anonymous$$y work-around has been to create a script that calls the State$$anonymous$$achineEnter/Exit methods when the state machine is entered/exited, no matter how that happens.

It requires me to use a custom subclass on State$$anonymous$$achineBehaviour that seals the normal State$$anonymous$$achineEnter/Exit methods and exposes it's own versions, which can be used to get the expected behaviour.

If you're interested, I can make a thread on the forums and post the code. I've been meaning to clean it up anyways, so it would probably help me get that done.

avatar image Eluem Baste · Dec 16, 2015 at 05:30 PM 0
Share

I would absolutely love to know more about how you did that.

In the end, that's actually the behavior that I'm looking to create.

I added another reply to this post though, where I discovered a work around that I believe actually does mimic the behavior I was originally describing in this post.

Thanks for the response.

avatar image Eluem Baste · Jun 27, 2016 at 02:58 PM 0
Share

@baste Hey, I'm still really curious as to how you went about making that custom subclass.

What does it use to hook into the "event" of leaving the entire statemachine? Does it use something to scan each frame if it changed or something? Or does it just run OnStateExit (so it hits every state in the substatemachine) and check if it's moving to a state that's outside of the statemachine?

I'd love to know!

avatar image Baste Eluem · Jun 30, 2016 at 11:05 AM 0
Share

Oh, didn't see your reply back in December. Sorry!

I've got a script that lives next to the animator. It scans the animator's controller, and finds two pieces of information:

1: What states has my custom State$$anonymous$$achineBehaviour on it. 2: Which states are substates of which substate machines.

Then, during runtime, I check which state the machine is in. If the state changes, I call the custom OnState$$anonymous$$achineExit on all of the state machines that have been left.

I've been meaning to put the code on GitHub, I'll do that soonish.

EDIT: Github

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Eluem · Dec 16, 2015 at 05:29 PM

I found a viable work around. It's still a cludge of sorts... but I THINK it achieves the exact overall behavior that I was describing.

If you create a placeholder Sub-Statemachine in the parent layer that has nothing in it except a transition straight from the entry node to the Up layer pointing to the parent statemachine, and then you create a transition from the original sub statemachine that was having issues to this statemachine, and point your states inside it to the exit node instead of the Up node, you can achieve what I wanted:

-Having the OnStateMachineExit fire -The parent entry node trigger -No dead frames (since instead of using a state to do the redirect, i'm using entry/up nodes, which don't consume a minimum of one update, they can pass through inside of an update [I believe])

However, this solution still doesn't address another problem... exiting the state machine due to an AnyState transition.

There really should be a sub state machine level method that is fired when the state machine itself is exited for any reason.

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 edwon · Sep 27, 2016 at 07:10 AM

Is there an "exit sub state machine" method yet? I could really use it!

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

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

Related Questions

OnStateEnter isn't updating in the correct order with normal update? 0 Answers

Sharing some but not all animator states between characters 0 Answers

Mecanim-Statemachine caches old version? (was: One Transition blocks other Transitions) 0 Answers

Transition Between Different Player States In Animator 0 Answers

Get time when the animation starts in Animator Controller 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