Instant AnimationState transition back into self is predictable?


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

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.