Download

State machine playing two states at the same time?

I have a more complicated animation graph and state machine going on and there a few things which I’m not sure is problem with my anim graph or if it’s a result of how sate machine is supposed to work and I just don’t know about that.
A very simplified example (which may not be very practical, but is there to show the point):

state_machine.jpg&stc=1

  • let’s say that the actor has pretty long acceleration and deceleration set in the standard movement component
  • character can go from idle to walk via typical rule of speed being above 0 and can go back to idle when speed is 0
  • can go from walk to run when speed is above 250 and can go back when it’s below 250
  • now the “special” rule governs when character can go from run directly to idle and this happens when you suddenly let go of controls (at which point the speed starts to get lower but thanks to deceleration it will happen over many frames)

What I’m observing while testing this setup is that if I’m in Run state, and suddenly let go of controls, the state machine correctly selects Idle and starts to transition from Run.
But what is also happening is that while it’s blending from Run to Idle, it also starts to blend to Walk (because of deceleration makes the character speed still above 0). Also it starts to blend from Walk back to Idle because meanwhile the speed has reached 0.

I know how could I fix this or avoid this. But it would be great to have confirmed that the described behavior is as expected for the reasons described above and I’m not seeing some bug, glitch or have some wrong idea about how is this supposed to work. So the core of the question is, if a state machine is “allowed” to select and play 3rd state while is transitioning from state 2 to state 1.

Thanks

This happens because it successfully blends to idle, says “wait, I need to blend from idle to walk because of this speed param!” and then blends back.

One GENERAL way you might fix this is to use some booleans; e.g. do not let Idle become walk unless an “is applying movement input” bool is set (you can do this by checking if the character movement current acceleration vector has a length near zero).

For this SPECIFIC instance, it might be easier to use a blendspace and just let a run-to-idle lerp across the walk state as it returns to idle (as a real human stopping slowly from a sprint will walk it out a bit as he slows down).

EDIT: sorry, I misread your question! The answer is “I’m pretty sure this is intentional”; the transition isn’t actually a TRANSITION. Once the rule is satisfied, AFAIK, it counts as being “in” the next state, the transition speed just controls the anim blending.

Thanks for the confirmation. Also it’s good to know that thing about transitions not being as a sort of intermediate state, but “only rules” that once they pass you are in the “selected” state.