- Home /
How do you properly attach Animation clips?
I have not worked with unity in a while (and I have never animated in it before) and now I am getting an error that has wasted a full day of work.
"The animation state X could not be played because it couldn't be found! Please attach an animation clip with the name 'X' or call this function only for existing animations."
All the online info I can find basically just says attach the animation to the game object and/or switch the rig to legacy. Research links (1), (2), (3), (4) and more.
Now, as far as I can tell my animation is attached (see image↓)
My rig is set to legacy and the top level game object has no imported animation in the Inspector, however this is expected as I am animating inside Unity rather then importing .fbx animation I have tried this as a prefab and without. The animation is on a single part (or parts) of the model. Will animation not work if it is on sub/grouped objects of the master FBX model?
I have an animation on a switch/Knob, when clicked it should animate to the off position and a blinking light stops blinking as well as turning off another light. Currently the switch loops back and forth between the off and on position and all the lights blink in an endless loop even with loop time unchecked. I can not find any good tutorials for animation in 4.1.3. The best I video tutorial have found was for an older version.
What am I doing wrong? How do you animate and que the animation to play clip by clip with C#? Why is my animation not showing up as attached? Any help would be greatly appreciated.
Here is a link to another person with a similar issue.
Is this a bug? has it been fixed in later versions?
Answer by Lazdude17 · Jun 05, 2014 at 05:48 PM
I haven't put an animation directly on my object so I don't know how that works, but you could use the Animator to do all this for you.
http://unity3d.com/learn/tutorials/modules/beginner/animation
^Unity's official tutorials on the subject. May help.
Thanks I will look at those I had found docs but not videos. Thank you so much.
I have an animation and an animator on the object as you can see in my image above. I tested on a friend using 4.5 and he did not get the same error message I am seeing. I would update to 4.5 but I am behind a fire wall and the IT process is lengthy. However if watching the vid's fails to help me I may be left with no other choice. Thanks again.
No problem. Just comment again if you need help. I'm using 4.3 and this works just fine for me. First just take the animation clip off of your object then the videos should explain the rest. Good luck ;)
O $$anonymous$$ i watched these and they are the same thing that the Documentation has. Its nice to watch ins$$anonymous$$d of read and get a visual but its nothing new and I am still stuck.
The one thing I noticed in a view of the videos is that his animation showed the model while $$anonymous$$e just shows a white arrow in a gray box. So my animation it seems is not attaching to the model but I still don't know how to make it attach.
As a test try making a simple sphere or cube. Click "Add Component" > "miscellaneous" and add an "animation" open the animation window (ctrl+6) and select "Add Curve". Name it something like bounce.anim Then select transform and the "+" next to position. Set a key at 0 and 1: then set a key at :30 and move the object down. record the animation. and hit play. The object will bounce up and down on screen. Turn off loop Time and it will only bounce once. Now make a code to make the animation play on a key code
using UnityEngine;
using System.Collections;
public class TestAnimation : $$anonymous$$onoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftShift)){
animation.Play("bounce");
}
}
}
and when the key is selected that's when I get the error?
I see posts about warp mode but all I see is loop time?
So I have been testing and I think I may have a solution. I hope it helps others.
The order things are added in is very important. The documentation and the videos do not make it very clear but if you are adding an animation, you need to make sure you add the animation component (animation not animator!) to the object before you click add curves. If you select the model and hit add curves it will add an Animator component not the animation component and then you will have both as is seen in my screen grab in the above question. When this happens the animator will not be attached and your scripts will throw errors.
Your answer
![](https://koobas.hobune.stream/wayback/20220613150809im_/https://answers.unity.com/themes/thub/images/avi.jpg)