Hello
I am getting this error (below is the code, the last line is where i get the error)
Invalid Layer Index
UnityEngine.Animator:GetCurrentAnimatorStateInfo(Int32)
The result is my charecter became invisible… it has an animator and the animator has 3 layers…
The most weir thing is, it do not happens always, some times yes and other no…
Any ideas?
Thanks!!!
void Update(){
state = animator.GetInteger("state");
switch (state){
case 0:
layer = 0;
idleState = idleState1;
break;
case 1:
layer = 1;
idleState = idleState2;
break;
}
currentBaseState = animator.GetCurrentAnimatorStateInfo(layer);
....
There are several places here where the error could have occurred. The resulting error is basically that the value (an integer) supplied to GetCurrentAnimatorStateInfo doesn’t map to any state info.
Places where it could have gone wrong:
state = animator.GetInteger("state") This function could’ve simply returned an invalid integer. Is "state" what you want to pass as argument?
Your switch statement only checks for the values 0 and 1 for state. if state has any other value, layer will never be initialized.
layer will only ever get the values 0 or 1. Does GetCurrentAnimatorStateInfo expect one of these values?
This is probably related to a Unity bug which has been going on for more than one year (since Nov 2013 from what I understand).
I am not sure whether Unity is addressing it.
layer is an integer right (int layer)?
– 767_2Yes it is.
– ddfire