Mecanim Problems (501266)

i have script.

static int atakState = Animator.StringToHash(“Base.Atak1”);

void Start (){
anim = GetComponent();
}

void FixedUpdate ()
{
currentBaseState = anim.GetCurrentAnimatorStateInfo(0);

if (currentBaseState.nameHash == atakState){
Debug.Log(“Do Stuff Here”);
}
}

But Unity throws this error.

error CS0103: The name `curentBaseState’ does not exist in the current context

Where is my mistake?

1 Like

On what line number the error is? (copy the complete error log message)

This is not the original script, and extract from it. However, swears to this specific part of it. To be more precise on what these lines.

currentBaseState = anim.GetCurrentAnimatorStateInfo(0);

if (currentBaseState.nameHash == atakState){

In this case, the error code they identical. Swears by the variable “currentBaseState”.

If you set the variable “currentBaseState” some type (int, string, float or whatever)

int currentBaseState = anim.GetCurrentAnimatorStateInfo(0);

it gives this:

error CS0029: Cannot implicitly convert type UnityEngine.AnimatorStateInfo 'to int’

int currentBaseState = anim.GetCurrentAnimatorStateInfo(0); will never work.

The doc’s tells you exactly what you expect the return to be:

which is function GetCurrentAnimatorStateInfo (layerIndex : int) : AnimatorStateInfo

So what your line should be is:

AnimatorStateInfo currentStateInfo = anim.GetCurrentAnimatorStateInfo(0);

Thank you. It worked. :slight_smile:

Hi, I have a question to you, I have a similar issue, actually I wrote the example in my code and I don´t have errors, but the numbers that are comparing never are the same, I mean, the number of the state I want to find is different from the number that GetCurrentAnimatorStateInfo gives to me, didn´t you have the same problem?