Animation is playing but GetCurrentAnimatorStateInfo is giving false value.Why?

Already a default animation is playing.I am playing the animation by setting animmove.SetBool("Movement", true); by creating a second layer in animator to play two animations simultaneously.I added the code in start method the animation works at start .I commented the above code to check whether its working and it was not working.So i made sure because of the code the animation was working.

When the animation stops I want to start another animation.

void Start()
    {
        animmove.SetBool("Movement", true);
    }
void Update()
    {
var aa = animmove.GetCurrentAnimatorStateInfo(0).IsName("Movement");
Debug.Log("Animation Value = "+aa ); //When I give 0 parameter it giving me false and novalue when I test for 1
    }

According to the screenshot, your state is called “Move”, not “Movement”.

1 Like

animmove.GetCurrentAnimatorStateInfo(1).IsName(“Move”);
need to change the parameter of GetCurrentAnimatorStateInfo also.

I changed to Move.You need to change the parameter also right?

 IEnumerator IsAnimationdone()
    {
        while (animmove.GetCurrentAnimatorStateInfo(1).IsName("Move") && animmove.GetCurrentAnimatorStateInfo(1).normalizedTime < 1.0f)
        {
            //Wait every frame until animation has finished
            yield return null;
        }
        Debug.Log("Animation has finished");
        //Do something
        speed = 10f;
        float step = speed * Time.deltaTime;
        animmove.SetBool("Movement", false);

        if (animmove.GetCurrentAnimatorStateInfo(1).IsName("Bite"))
        {
           
            Showprefabs.transform.GetChild(0).GetComponent<Animator>().enabled = false;
            Showprefabs.transform.GetChild(0).position = Vector3.MoveTowards(Showprefabs.transform.GetChild(0).position,
                                                                            new Vector3(Arcam.transform.position.x, Arcam.transform.position.y + 0.2f,
                                                                                        Arcam.transform.position.z + 6.3f), step);
          
        }
    }

Here the animation doesnt play.For some reason the Debug displays Animation has finished.If I remove the line animmove.SetBool(“Movement”, false); the animation play but cannot figure out when the animation has finished.Any idea what I am doing wrong here

Nothing is obviously jumping out at me as a likely reason for the animation to not play, but there are always plenty of possibilities for things to go wrong when using Animator Controllers and even at the best of times it’s not entirely clear what the system is doing internally. I can’t see your Console window, but that’s always the first thing to check. But beyond that there isn’t really any standard advice I can give you for debugging an Animator Controller because everyone seems to run into entirely different issues.

If you get sick of wasting time investigating silly issues like that, you might be interested in Animancer (link in my signature) which lets you avoid Animator Controllers and just control everything with scripts. It has several easy ways of waiting for animations to finish built into it.

1 Like

I dont know what I did.I removed the IEnumerator and just gave the below code and it started working.I did not use this condition in if(animmove.GetCurrentAnimatorStateInfo(1).IsName(“Move”)).

if (animmove.GetCurrentAnimatorStateInfo(1).normalizedTime > 1)
            {
               
                animmove.SetBool("Movement", false);
                if (animmove.GetCurrentAnimatorStateInfo(1).IsName("Bite"))
                {
                    Showprefabs.transform.GetChild(0).GetComponent<Animator>().enabled = false;
                  
                   //   Trying to update the position of prefab in front of the ARcamera(real close).But not happening.When the app starts it takes that position as camera position.How to update it.?          
                    Showprefabs.transform.GetChild(0).position = Vector3.MoveTowards(Showprefabs.transform.GetChild(0).position,
                                                                                    new Vector3(Arcam.transform.position.x, Arcam.transform.position.y ,
                                                                                                Arcam.transform.position.z +6.3f), step);

                   
                }

            }