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\$
5
\$\begingroup\$

Just add a check:

foreach (AnimatorControllerParameter parameter in playerAnimator.parameters) {
    if (parameter.type == AnimatorControllerParameterType.Bool)
        playerAnimator.SetBool(parameter.name, false);
}
\$\endgroup\$
  • \$\begingroup\$ Where did you get such knowledge? \$\endgroup\$ – Yaroslav Jun 17 '17 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 '17 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.