0
\$\begingroup\$

In C#, how would I get the number of animations in an Animator Controller?

So I want to find out how many animations there are in an Animator Controller, and have this number in script.

Thanks in advance!

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

[SerializeField] Animator animator; int NumberOfNonEmptyStates = animator.runtimeAnimatorController.animationClips.Length;

This returns the number of non-empty states in the specified animator. (I'm using Unity version 2018.3.4)

\$\endgroup\$
-2
\$\begingroup\$

If you are using Version 5 and up, you can get all states in the Animation Controller. You will need to drill down to layer, state-machine and then finally state.

Follow these to get started:

http://docs.unity3d.com/ScriptReference/Animations.AnimatorController.html http://docs.unity3d.com/ScriptReference/Animations.AnimatorController-layers.html http://docs.unity3d.com/ScriptReference/Animations.AnimatorControllerLayer-stateMachine.html http://docs.unity3d.com/ScriptReference/Animations.AnimatorStateMachine.html

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Could you provide an example of code of how I would get the number of animations from an Animator controller? \$\endgroup\$ Commented Apr 14, 2017 at 10:48
  • \$\begingroup\$ Follow the links, they'll tell you how. The docs list all the members you need to access and they explain each one and what it gives you back \$\endgroup\$ Commented Apr 14, 2017 at 11:27
  • 4
    \$\begingroup\$ -1 Link only answers are quite worthless. Links rot. Additionally, the answer doesn't seem to answer the question. \$\endgroup\$ Commented Apr 14, 2017 at 17:08

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.