AnimatorControllerParameter

class in UnityEngine

/

Implemented in:UnityEngine.AnimationModule

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.

Did you find this page useful? Please give it a rating: