- Home /
Instant AnimationState transition back into self is predictable?
Hello,
In StateMachine Behaviors, is there a way to do the following:
From the OnStateExit()
, check if the state is in transition, and is in fact transitioning back into self?
if (animator.IsInTransition(layerIx) == false) {
return false; //always returns here :(
}
AnimatorStateInfo next_state = animator.GetNextAnimatorStateInfo(layerIx);
AnimatorStateInfo curr_state = animator.GetCurrentAnimatorStateInfo(layerIx);
if (next_state.fullPathHash == curr_state.fullPathHash) {
return true; //loops into self
}
Even if I comment "is in transition block" the next_state
has fullPathHash
as zero, although the state does transition into self. My transition back into self has length of 0.0 in mecanim, so it's instant.
thank you
Answer by IgorAherne · Mar 18, 2017 at 01:31 AM
Ok I've solved it by signing up to an external monobehavior singleton, into its dictionary of function pointers.
That singleton skipped one frame, then invoked all those function pointers for whome 1 frame has passed.
Singleton then removed all such invoked functions.
The functions themselves did a simple check within their StateMachineBehavior to see if the state's script's _myCached_fullPathHash_ofMyState
is the same as _animator.GetCurrentAnimationStateInfo(_cachedLayerIx).fullPathhash
Because it was called 1 frame later, such deferred functions could see if there is a mismatch betweent he CUrrentAnimationStateInfo's hash and the previously stored one. In that case, I could assume the StateMachine behavior was existed sucessfully, and didn't, say, loop back into itself.
Your answer
![](https://koobas.hobune.stream/wayback/20220612113253im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Not able to use a Vector as a condition in Mecanim? 2 Answers
Animator not registering changes in parameters. 0 Answers
NavMeshAgent animation - sliding 2 Answers
How do you play an animation in reverse? 0 Answers
Get length from state in Animator 1 Answer