- Home /
Unity thinks my animation is not attached, but it is.
I am currently trying to make a soldier play an animation for a third person view for my multiplayer game. I had just imported the BootCamp soldier in for a placeholder, along with all the animations. In my script, I had wrote:
anim.animation.CrossFade("Standing");
And apparently the Unity Console tells me the animation 'Standing' is not attached to the anim GameObject, but it clearly is. The complete error is the following:
The animation state Standing could not be played because it couldn't be found!
Please attach an animation clip with the name 'Standing' or call this function only for existing animations.
UnityEngine.Animation:CrossFade(String)
MultiplayerMulti:UpdateAnimations() (at Assets/_Scripts/MultiplayerMulti.js:56)
MultiplayerMulti:Update() (at Assets/_Scripts/MultiplayerMulti.js:35)
MultiplayerMulti line 56 is just the line I had provided above.
As you can see, it is CLEARLY attached to my Soldier object. And yes, the soldier object IS SET AS THE GameObject for the anim variable! Any idea what the real problem is is appreciated.
Thanks in advance, william9518
Please paste the complete console message into a comment, as well as the code that sets anim. Also, add this line and provide the output (assu$$anonymous$$g C#):
Debug.Log("anim is " + anim.name);
Alright, and I have already debugged the anim variable.
Can you play the animation on the character in the Animation View window?
Also, before the anim.animation.CrossFade("Standing"); line, try enumerating all the clips in the Animation component. You could add a couple lines like this:
foreach (AnimationState state in anim.animation) {
Debug.Log(string.Format("[{0}]", state.name));
}
I added square brackets above so you can see if maybe the animation clip has a blank space at the beginning or end of the name.
Answer by william9518 · Oct 11, 2013 at 01:27 AM
I fixed it by not doing it at all. I revamped the system with Animators.
Answer by tanuj0092 · Oct 10, 2013 at 04:46 AM
Probably the question description is still unclear whether you are directly using the object or instantiating the object . However, there are several possibilities in your case. First, in the image you are showing is the prefab of the soldier on which the animation is attached. Check whether the object which is placed in the scene i. e. the hierarchy, the animation is attached to it or not. If not then you probably need to redrop the object. If it doesn't work then you need to instantiate the object through code.
It is showing you the error just because the object present in the hierarchy doesn't have the animation file attached to it. Do one thing, place your object in the hierarchy from the project window, check whether Animation is attached to it, use that object as a reference through the script and instantiate that object. It would definitely work.
It is being instantiated through code. Also, I am using Network.Instantiate, so I cannot instantiate anything that is not a Prefab.