- Home /
Animator.parameterCount returns 0 after saving project in editor
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:
[CustomEditor(typeof(Animator))]
public class testScript : Editor
{
private Animator anim;
private void OnEnable()
{
anim = (Animator)target;
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
Debug.LogFormat("{0} - {1}", anim.name, anim.parameterCount);
serializedObject.ApplyModifiedProperties();
}
}
This is my isolated scene setup in a new, clean project. 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?
Answer by _tink_ · Oct 08, 2021 at 10:01 AM
I have stumbled upon the exact same problem. Initially, I have a correct number of parameters and after adding or deleting one, Animator.parameters return zero and a warning pops up. What resolved it, was "turn it off and on" approach:
animator.enabled = false;
animator.enabled = true;
Debug.Log("Parameters count: {animator.parameterCount}");
...
Ah, that's interesting! I don't think I have the project anymore to check whether it works for me, but I could easily recreate it. What version of Unity are you using? Perhaps that has something to do with it as well. I believe I was using Unity 2019.3 when I posted this.
Thanks, I'll do some tests with your proposed solution later this week and post my findings.
Your answer
![](https://koobas.hobune.stream/wayback/20220612234339im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to move Animation Clips into Animator Controller? 1 Answer
unity freezes when running sprinting animation 0 Answers
the Story of GetSpectrumData, Animator and IEnumerator :D 1 Answer
How to script SetTrigger (JS)? 1 Answer
Building Tilemap Animations in code require AnimationController 0 Answers