How to check if animator animations has finished

I currently have this issue of properly transitioning one animation to the next after it has finished.
Im previously used statemachinebehaviour to disable variables from this thread

This is my script

if (player_movement.VaderAttack1 == true)
        {
            anim.SetBool("VaderAttack1", true);
            //detects when 1st animation has ended before starting the second
            if (player_movement.VaderAttack2 == true && !anim.GetCurrentAnimatorStateInfo(0).IsName("Vader attack1")) //check when 1st attack anim has finished and 2nd anim has been called
            {
                anim.SetBool("VaderAttack2", true);

               
            }
            else if (player_movement.VaderAttack2 == false && anim.GetCurrentAnimatorStateInfo(0).IsName("Vader attack1") && anim.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1.0f) //check if 2nd anim isnt called and disable 1st anim var after it is finished
            {
                player_movement.VaderAttack1 = false;
                anim.SetBool("VaderAttack1", false);

            }

            if (player_movement.VaderAttack2 == true && !anim.GetCurrentAnimatorStateInfo(0).IsName("Vader attack2")) //disables 2nd anim var after it finishes
            {
                anim.SetBool("VaderAttack2", false);
                player_movement.VaderAttack2 = false;
                player_movement.VaderAttack1 = false;
            }

This would be super easy with Animancer (link in my signature) using its End Events.

I’m not sure exactly what you’re trying to achieve, but if you just want to make a simple attack combo system then the Weapons example explains how I would do it.

1 Like

Alright thanks, ill try the end events out.
I got my own weapon combo working, but the game doesnt want to detect when an animation has finished so Ill keep your tutorial in mind.

Bump
is there any way to do this without hooking all my animations to another plugin? Trying to see my options 1st

if the normalized time of a state is greater than 1, it means the animation has played one full loop

public Animator animator;
AnimatorStateInfo animStateInfo;
public float NTime;

bool animationFinished;


animStateInfo = animator.GetCurrentAnimatorStateInfo (0);
NTime = animStateInfo.normalizedTime;

if(NTime > 1.0f) animationFinished = true;
3 Likes

Now Im just detecting if the animation is running, but when both both the animator bool and normal bool are enabled, while the animation is stuck at the end without transitioning anywhere, the elseif statement doesnt succeed.

else if (anim.GetBool("VaderAttack1") == true && anim.GetCurrentAnimatorStateInfo(0).IsName("Vader Attack1"))
            {
                player_movement.VaderAttack1 = false;
                anim.SetBool("VaderAttack1", false);
                anim.Play("Idle");

            }

7092979--844837--upload_2021-4-30_13-8-9.png

this is quite complicated way to do it (and I just realized you already were using ntime>1 in the first post)
but anyway

I see you have a different name for state
in code: Vader Attack1
in animator: Vader attack1

1 Like

Thanks for pointing out this. Finally fixed it