- Home /
This question was
closed Mar 17, 2020 at 07:00 PM by
Fa6ex for the following reason:
The question is answered, right answer was accepted
Question by
Fa6ex · Mar 17, 2020 at 06:45 PM ·
animatorparametersindexget
Get Animator parameter index by name
Is there a way to get an Animator parameter index by name, like you can do with layers?
Comment
Best Answer
Answer by Fa6ex · Mar 17, 2020 at 07:00 PM
Never mind, I found a workaround. Here it is, if someone else happens to have this problem:
public byte GetAnimatorParameterIndex(string paramName)
{
for(byte i = 0; i < anim.parameters.Length; i++)
{
if(anim.parameters[i].name == paramName)
{
return i;
}
}
Debug.LogError("Parameter " + paramName + " doesn't exist in the animator parameter list!");
return 0;
}
There is a function for that:
https://docs.unity3d.com/ScriptReference/Animator.StringToHash.html
That gives a hash code not the parameter's index.