Quantcast
Channel: Questions in topic: "state machine"
Viewing all articles
Browse latest Browse all 42

Identifying a transition to self in StateMachineBehaviour

$
0
0
Hello, ---------- I have a class that extends [StateMachineBehaviour][1] 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. [1]: https://docs.unity3d.com/2019.3/Documentation/ScriptReference/StateMachineBehaviour.html

Viewing all articles
Browse latest Browse all 42

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>