2
\$\begingroup\$

How can I change all boolean parameters of an animator to false?

Here is a solution which I found:

foreach (AnimatorControllerParameter parameter in playerAnimator.parameters)
{
    playerAnimator.SetBool(parameter.name, false);
}

The problem with this solution is that I will get a warning in console if my parameter in Animator is not a boolean. I would not like to be getting that. So, I need somehow to being able to take only parameters of type boolean.

\$\endgroup\$

1 Answer 1

5
\$\begingroup\$

Just add a check:

foreach (AnimatorControllerParameter parameter in playerAnimator.parameters) {
    if (parameter.type == AnimatorControllerParameterType.Bool)
        playerAnimator.SetBool(parameter.name, false);
}
\$\endgroup\$
2
  • \$\begingroup\$ Where did you get such knowledge? \$\endgroup\$
    – Yaroslav
    Jun 17, 2017 at 16:24
  • 1
    \$\begingroup\$ You can find the info about the AnimatorControllerParameter class in the Unity docs: docs.unity3d.com/ScriptReference/… - please don't forget to accept the answer if it solved your problem. :) \$\endgroup\$
    – Galandil
    Jun 17, 2017 at 16:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .