But that is very messy and inefficient. I know there would be a way to loop through each parameter with a for loop and I’ve looked up ways of doing this but it’s not working. I’ve tried this:
for (int i = 0; i < anim.paramaters.Length; i++)
{
anim.ResetTrigger (i);
}
And although the above code does loop through each parameter, it does not reset the triggers nor the booleans using the i variable.
ResetTrigger(int) takes the hash of the parameter name. Sadly, there’s no way to get the states of the animator controller at runtime.
The easiest thing is to build an array of the hashes at startup:
private int[] boolHashes;
void Awake() {
boolHashes = new int[] {
Animator.StringToHash("isIdle");
Animator.StringToHash("isWalking");
Animator.StringToHash("isJumping");
...
};
}
...
// when you want only isWalking true
foreach(var hash in boolHashes) {
anim.SetBool(hash, false);
}
anim.SetBool("isWalking", true);
Alternatives is to design your animator so you don’t have to do this, or use a different way of animating. SimpleAnimation is a good alternative. Somebody linked the lite version of Animancer the other day, it looked pretty decent as well.