Any way to wait for animation play after animator.Play in the same frame?

Result:
Enemy Original (1) d 352
Enemy Original (1) i 352

As you can see, the character start defend animation, but the defend animation have not start yet, and character is still in Idle animation (actionMode become Idle immediately in the same frame)

Any suggestion?

 void FixedUpdate()
    {    
        switch (actionMode)
        {
            case UnitActionMode.Idle:
              
                break;

            case UnitActionMode.Melee:

                if (animator.GetCurrentAnimatorStateInfo(currentAnimationLayer).IsName("Idle"))
                    actionMode = UnitActionMode.Idle;

                break;

            case UnitActionMode.GetHit:

                if (animator.GetCurrentAnimatorStateInfo(currentAnimationLayer).IsName("Idle"))
                    actionMode = UnitActionMode.Idle;

                break;

            case UnitActionMode.Defend:

                if (animator.GetCurrentAnimatorStateInfo(currentAnimationLayer).IsName("Idle"))
                {
                    Debug.Log(transform.name + "  i   " + Time.frameCount);
                    actionMode = UnitActionMode.Idle;
                    animator.applyRootMotion = false;
                }
break;
}
}

  public void Defend()
    {      
        if (actionMode == UnitActionMode.Idle)
        {
            Debug.Log(transform.name + "  d   " + Time.frameCount);
            animator.applyRootMotion = true;
            animator.Play(_unarmed_Strafe_Back);
            actionMode = UnitActionMode.Defend;
        }

    }

“wait…in the same frame” doesn’t really make sense. A frame is a frozen moment in time. Game time doesn’t pass until you go to the next frame.

It looks like you already have a variable “actionMode” that keeps track of what action you are trying to perform. If you want to know what animation is “supposed” to be playing, can you use that instead?

If you are trying to determine when the animation ends, you could consider putting events on the animations to notify your scripts when specific points are reached. Or maybe just have a special exception for “I already changed the animation this frame so don’t try to read it until next frame”.