- Home /
No animation attached to gameobject?
So, i've been looking for an answer for 2 hours now, and i can't seem to find any solution to my problem.
Error :
MissingComponentException: There is no 'Animation' attached to the "Door_Pivot" game object, but a script is trying to access it.
You probably need to add a Animation to the game object "Door_Pivot". Or your script needs to check if the component is attached before using it.
UnityEngine.Animation.Play (System.String animation)
Code :
GetComponent.<Animation>().Play("DoorClose")
And, i have attached the Animator thing to my game object, and i have attached the 2 animations called : DoorOpen and DoorClosed. I have also tried using 2 "AnimationClip" variables to find the animations, but it didn't work either. I used variables to attach the 2 animations (var type : AnimationClip), and it gave me same error, that it's not attached. It's obviously there! I'm so confused this doesn't make any sense.
I can't remember the details of how animations are handled in unity atm, as it seems to be somewhere in between transitioning to mecanim. but from the look of the error, you may be adding the 'wrong' animation component (an animator ins$$anonymous$$d of an animation?), try the following:
Animation anim = GetComponent.<Animation>();
if(anim == null) anim = AddComponent.<Animation>();
anim.Play("DoorClose");
Unity says "$$anonymous$$ identifier : AddComponent". So i changed it to GetComponent and got the exact same error like before.
So I think @Scribe got the point, you have no Animation component attached.Just go back to the editor, remove the animator component, add an animation component, and everything will work like charm. As far as I can guess :)
EDIT..... : So, i now understand what you meant by adding the animation to the script. Did that and now i have another error....
Heres the error : The animation state DoorOpen could not be played because it couldn't be found! Please attach an animation clip with the name 'DoorOpen' or call this function only for existing animations.
Super, almost there, Now it said that although you have an animation component, but you failed to drag the animation clip into the component. So you have to drag the clip created before to the animation box. After that you will be able to play it. If you have no animation clip ready, record it save it, and you are ready to go. If you need help in creating the animation clip just let us know.
Answer by HappyCrayfish · May 05, 2015 at 02:08 PM
Credit to these guys who helped me solve the problem. (i think this is how to tag people....) - @zeppike - @Scribe
So, heres the answer : I used a Animator component instead of an animation one. The animation component can be found by searching for one. When you have attached it, you will need to add your animation(s) to it by dragging them to the animations "spot". Now, i recommend you unchecking "Play automatically" since it will just loop the animation if this is checked. Then, write this in your script to play the animation.
this.GetComponent.<Animation>().Play("Animation_name_Here");
(this) simply means that i'm targeting the object that the script is attached to, so if I'm correct you should be able to put the name of other object in there too. (not sure though).
I know this is an old post but if anyone is looking at this you have to remove the dot between GetComponent and
Solved: this.GetComponent().Play("Animation_name_Here");
Answer by ANLevant · Feb 14, 2018 at 05:35 AM
I'm having sort of the same problem, I even tried adding an animator on the object, but the problem is the parent object is also in an animator and for some reason it aint animating the god damned thing, its very weird
Hey man did you try to use "public AnimationClip nameOfYourAnim" ins$$anonymous$$d of "public Animation nameOfYourAnimation".
Your answer
Follow this Question
Related Questions
I can't edit my animation or play my other animation 0 Answers
Trying to get a sword swinging animation to play on mouse button 1 (unity 5) 2 Answers
Simple go forward and turn back loop movement stuck to the limit without reverse 2 Answers
How would you reccommend adding the jumping animation to my script? 0 Answers
How to get a animation to play without changing the pozition the gun is in when aming down sights 0 Answers