Not sure if I’m doing something wrong here or totally lost in the way the system works.
Here is the situation:
I have an actor on the floor and handcuffed, his animation state is called handcuffedIdleState.
When the other actor beats him up he will go to a new state called handcuffedKickedInHeadState by using a trigger:
animController.anim.SetTrigger("isKickedInHead");
Once that animation has played, he returns to the original state handcuffedIdleState.
I need to know when the actor has finished the handcuffedKickedInHeadState so I can trigger his reaction. To do that I run the following function on Update():
if(animController.currentBaseState.nameHash == animController.handcuffedIdleState){
//React to kick
}
Now my problem is, since he STARTED on handcuffedIdleState, this will immediately be true, even before the animation started.
So I decided to add a couple more lines.
//Make sure the 'isKickedInHead' trigger is no longer true AND
//That the animation is not in transition
if(
!animController.anim.GetBool("isKickedInHead") &&
!animController.anim.IsInTransition(0) &&
animController.currentBaseState.nameHash == animController.handcuffedIdleState
){
//React to kick
}
But still, this is immediately true even before the handcuffedKickedInHeadState started. I can’t figure out a sure way of knowing when the new animation has finished and I’ve arrived at the Idle State…
UPDATE - Another way to look at the problem
So the main issue here is that I’m returning to the animation I started.
I’m going from A(1) → B → A(2) and I’m trying to figure out when I’m back at A.
B can be anything so its not something I can rely on. B can be a different state so putting events on B or even trying to track it is not an option.
This is what I usually do:
if(
!animController.anim.IsInTransition(0) &&
animController.currentBaseState.nameHash == animController.stateA
){
The problem is, once the transition is over, for ONE frame, before B becomes the currentBaseState, A(1) is the currentBaseState. This makes it impossible to use A for the comparison…
In case I’m not being clear, here is a little graphic I did for myself to understand the problem (the orange box is the problematic frame):