Version: Unity 6.1 Beta (6000.1)
LanguageEnglish
  • C#

AnimatorControllerParameter

class in UnityEngine

/

Implemented in:UnityEngine.AnimationModule

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Used to communicate between scripting and an AnimatorController.

You can add an AnimatorControllerParameter to an AnimatorController in the Animator window or with the function AnimatorController.AddParameter in script. At runtime, use the following functions to set the value of a parameter in the Animator:

You can also set parameter values in the Animation window based on Animation Curves in Animation Clips.

using UnityEditor;
using UnityEditor.Animations;
using UnityEngine;

// This example demonstrates how to create an AnimatorController with some default parameters.
public static class AnimatorControllerParameterExample
{
    [MenuItem("Example/Create Animator Controller With Default Parameters")]
    public static void CreateAnimatorControllerWithDefaultParameters()
    {
        // Create a new AnimatorController.
        var controller = AnimatorController.CreateAnimatorControllerAtPath("Assets/NewControllerWithParameters.controller");

        // Add a new parameter to the controller.
        var speedParameter = new AnimatorControllerParameter
        {
            name = "Speed",
            type = AnimatorControllerParameterType.Float
        };
        controller.AddParameter(speedParameter);

        // Add another parameter to the controller with a default value.
        var isGroundedParameter = new AnimatorControllerParameter
        {
            name = "IsGrounded",
            type = AnimatorControllerParameterType.Bool,
            defaultBool = true
        };
        controller.AddParameter(isGroundedParameter);

        // Save the controller.
        AssetDatabase.SaveAssetIfDirty(controller);
    }
}

Additional resources: AnimationParameters manual. AnimatorController.RemoveParameter for removing parameters. AnimatorController.parameters for accessing the list of parameters.

Properties

defaultBoolThe default bool value for the parameter.
defaultFloatThe default float value for the parameter.
defaultIntThe default int value for the parameter.
nameThe name of the parameter.
nameHashReturns the hash of the parameter based on its name.
typeThe type of the parameter.