- Home /
Check if clip exists in Animator
How do I check if an animation clip exists in the controller attached to the animator component?
When a clip doesn't exist I get an error.
Animator.GotoState: State could not be found UnityEngine.Animator:Play(String).
So I need something like
if(hasClip("idle"))
GetComponent<Animator> ().Play ("idle");
I know of Animation but that is deprecated, so how do I do this with Animator in Uity 4? I am not using Legacy.
Answer by getyour411 · Aug 14, 2015 at 05:31 AM
https://unity3d.com/learn/tutorials/modules/beginner/animation/animator-scripting
See StringToHash example too
That doesn't check if "jump" exists AFAI$$anonymous$$, it just checks if "run" is currently playing. How can I check if "jump" exists so I wouldn't get an error trying to play the jump clip?
Answer by Pawl · Apr 09, 2016 at 01:16 AM
I believe HasState() has been added with Unity 5 (however I do not see it available in my current Unity 4.6.9 project)
http://docs.unity3d.com/ScriptReference/Animator.HasState.html
Your answer
![](https://koobas.hobune.stream/wayback/20220611235818im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
2D Animation does not start 1 Answer
Playing one animation after another through Animator Controller 2 Answers
2D Shooting Delay with Animation 2 Answers
A* Pathfinding project with mecanim animation 0 Answers
Setting an animation 1 Answer