Search Unity

How to get Animator parameters NOT at runtime

Discussion in 'Scripting' started by Mike99, Oct 30, 2018.

  1. Mike99

    Mike99

    Joined:
    Dec 11, 2011
    Posts:
    160
    Hi,

    I'm trying to display all parameters' names of a given Animator in the editor.

    It's ok except when I change something in the parameters (adding, modifying...), the editor doesn't reflect this change. I have to play/stop to get the changes in the Editor.

    Any idea how to do that ?
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
  3. neilsarkar

    neilsarkar

    Joined:
    Aug 11, 2017
    Posts:
    11
    For animator parameters in editor, you'll want to use
    UnityEditor.Animations.AnimatorController


    Code (CSharp):
    1. public class Foo: Monobehaviour {
    2.   void OnValidate() {
    3.     var animator = GetComponent<Animator>();
    4.     var animatorController = animator.runtimeAnimatorController as UnityEditor.Animations.AnimatorController;
    5.    
    6.     foreach (var trigger in animatorController.parameters) {
    7.       Debug.Log(trigger.type + " " + trigger.name);
    8.     }
    9.   }
    10. }
     
    gattusoarthur likes this.
  4. gattusoarthur

    gattusoarthur

    Joined:
    Apr 29, 2020
    Posts:
    5
    Thanks. This is very helpful.