- Home /
Animation State OnStateEnter getting previous state
We have an OnStateEnter behavior that will randomly select a transition. But we would like the ability to do something special if it is coming from a specific state.
I don't see a way to determine what the prior state was in OnStateEnter. Most state machines have that kind of functionality. Is there a way?
Otherwise, we need to complicate the state machine by making a special state for that return.
Also checked OnStateExit and that doesn't say where it is going either. It makes it very hard to do anything custom if you don't have info about what is happening in the state machine.
I tried also animator.GetNextAnimatorStateInfo(layerIndex); but this doesn't seem to be the "next state" as you would think in an OnExit.
I got around the problem a hacky way. Added a local variable in the Behavior that I just set from the main game when I set that any. I check if the behavior exists then set the flag. Sure there is a better way but couldn't find it.
Your answer
Follow this Question
Related Questions
State Machine Behaviour public variable not assignable from editor? 2 Answers
Animation State Machine Script Control Issue 1 Answer
Animation state machine not playing animation on triggered state 1 Answer
Easier way of creating transitions in the animator? 1 Answer
Why does Unity animator makes calling children's SetActive fail? 0 Answers