# Initiated a animation in unity via use of an animator component

I've written a coroutine that starts an animation.

GameObject.FindWithTag(names[number]).GetComponent<Animator>().StartPlayback();


This is the line of code that I wrote to start the animation. However, the animation does not start. I've even replaced the GameObject.FindWithTag(String) method with a reference to the actual object by declaring a GameObject in the script and setting it to a particular object in Unity's IDE. The animation still didn't start. Also, I must say the GameObject does have an animator component, you can see it in the inspector panel. No error messages can be seen in the console during play mode. What can I do to get the animation to play when I want it to play.

• You must instead use GetComponent<Animator>().Play(stateName, layer, normalizedTime) or GetComponent<Animator>().Play(stateNameHash, layer, normalizedTime) - Unity Docs for Play – Nikaas May 31 '17 at 20:03
• tried calling that on the animator component. Called anim.Play("light1",-1) becuase the name of the animation file is light1 and idk how to get the number representation of the base layer so I just put -1. That didn't work. What should the parameters be? – Joel J. May 31 '17 at 20:52
• Check the next tutorials and watch the whole section about Controlling Animation – Nikaas May 31 '17 at 21:14
• I went through those once. It didnt help me find a solution. maybe i missed something, ill watch again. – Joel J. May 31 '17 at 21:21

Apparently on this site I don't have enough "rep" to comment. Animators should begin playing automatically, so the problem is not with how you're "starting" it. Ensure that

-The animator component is enabled

-The game object is enabled

-The state you want to play is the default

-The animator isn't transitioning to another state at the beginning

Barring that, if you are trying to explicitly tell the animator what state to play, you need to name the state, not the name of the animation file.

• the animator and game object are enabled. the state name is the same as the animation file (shown in the picture above). How do I know whether or not the animator isn't transitioning to another state? – Joel J. Jun 1 '17 at 20:33
• does the entry state count, or does the transition need to be a state I created? – Joel J. Jun 1 '17 at 21:04
• The default state will be orange (like in the pic). Everything looks fine there. Try this, with your game object selected, press play and then look in the animator window. You should see a bar under the Light1 state showing that it is playing. – Mike Jun 2 '17 at 4:19
• I fixed the problem yesterday. I used an empty state as the default. and used the Play() method to start the desired animation. It worked – Joel J. Jun 3 '17 at 1:13
• @JoelJ. if you happen to come back, I recommend adding your solution as an Answer and accepting it. This makes the fix more visible to future users who have similar problems (and you can accrue up-votes for sharing a useful answer!) – DMGregory Sep 27 '18 at 12:28