Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Question How to change animator controller parameter value via editor script?

Discussion in 'Editor & General Support' started by a690089735, Dec 3, 2022.

  1. a690089735

    a690089735

    Joined:
    Dec 3, 2022
    Posts:
    10
    I can use code like this to create an animator controller (a file with .controller suffix)
    Code (CSharp):
    1. var controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath("Assets/Mecanim/StateMachineTransitions.controller");
    2. controller.AddParameter("FBBIKWeight", AnimatorControllerParameterType.Float);
    Then select it in the project window, it looks like this:

    This file is not referenced to any Animator, This is also the result I want, that is, the animator controller is just a .controller file.
    but I want the value of FBBIKWeight to be 1.0, but, not found a function like "animatorcontroller.parameters[0].value = 1.0f".
    Currently I can only change this value in the window, however I have thousands of files, so,how should I set the parameters in the animator controller to 1?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    33,673
    There is another overload of the
    AddParameter()
    method that accepts a
    AnimatorControllerParameter


    Always start with the documentation. :)
     
  3. a690089735

    a690089735

    Joined:
    Dec 3, 2022
    Posts:
    10
    Very cool, just pre-define the defult value and then add the parameter.
    Thank you very much.
    Hah, even vscode told me there was 1 overload, I didn't see it.:D