Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Animator.parameterCount returns 0 after saving project in editor

Discussion in 'Editor & General Support' started by ChefBaas, May 15, 2020.

  1. ChefBaas

    ChefBaas

    Joined:
    Jul 25, 2018
    Posts:
    2
    I'm trying to create an editor script which displays an animator's parameters. However, as soon as I save my project (after making any change), animator.parameterCount returns 0. A warning also appears saying Animator is not playing an AnimatorController. The warning references UnityEngine.Animator:get_parameterCount() specifically as the source of the warning.

    I did an isolated test using the following script:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEditor;
    5.  
    6. [CustomEditor(typeof(Animator))]
    7. public class testScript : Editor
    8. {
    9.     private Animator anim;
    10.  
    11.     private void OnEnable()
    12.     {
    13.         anim = (Animator)target;
    14.     }
    15.  
    16.     public override void OnInspectorGUI()
    17.     {
    18.         base.OnInspectorGUI();
    19.  
    20.         Debug.LogFormat("{0} - {1}", anim.name, anim.parameterCount);
    21.         serializedObject.ApplyModifiedProperties();
    22.     }
    23. }
    I included my scene set-up (I created a new project for this test). You can see in the console that initially the correct number of parameters were printed. Then I made a simple change, saved the project and both the warning and the second print popped up immediately.

    Note that in the actual project the animator does have an avatar, states, everything, but the exact same behaviour occurs.

    Does anyone know whether I'm doing something wrong? Am I not supposed to be able to access the parameterCount outside playmode?
     

    Attached Files: