- Home /
Identifying a transition to self in StateMachineBehaviour
Hello,
I have a class that extends StateMachineBehaviour attached to some of my Animator states. These states have transitions with "transition to self" enabled. After some testing, it looks like when a state transitions to itself, OnStateEnter()
is not called again.
My problem is that I would like to treat a transition to self the same as I would treat any other transition to this state, i.e. go through the normal flow of calling OnStateEnter()
and OnStateExit()
like any other state transition would. Is there a slick way to do this?
The best approach I've thought of so far has a strong workaround feel to it. Basically catching the current clip time in OnStateUpdate()
and evaluating it against the current clip time of the previous frame. If it's less than the previous frame's clip time, then consider it to be a self-transition and call OnStateExit()
and OnStateEnter()
explicitly. I wrote this out, and if I want to keep it then there's some debugging to do, but I'm hoping someone else has something better in mind.
It's strange, because this seems like a usecase that many others would have run into as well, but I haven't found any related posts around the web. Anyways, thanks for reading. Any insights would be appreciated.
Your answer
Follow this Question
Related Questions
Animator dont transition to self or any sub state 2 Answers
Make mecanim transition after a delay in Unity3D 0 Answers
Problem with GUI animation transitioning. 1 Answer
How to access and modify an animator state transition in runtime? 1 Answer
State Machine Behaviour public variable not assignable from editor? 2 Answers