• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by HappyCrayfish · May 01, 2015 at 04:56 PM · animationjavascriptunity5

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.

Comment
upariver
joao2fast4u

People who like this

2 Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Scribe · May 01, 2015 at 04:58 PM 1
Share

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 instead of an animation?), try the following:

 Animation anim = GetComponent.<Animation>();
 if(anim == null) anim = AddComponent.<Animation>();
 anim.Play("DoorClose");
avatar image HappyCrayfish · May 02, 2015 at 07:50 AM 0
Share

Unity says "Unknown identifier : AddComponent". So i changed it to GetComponent and got the exact same error like before.

avatar image zeppike · May 02, 2015 at 08:02 AM 1
Share

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 :)

avatar image HappyCrayfish · May 02, 2015 at 04:09 PM 0
Share

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.

avatar image zeppike · May 02, 2015 at 07:00 PM 1
Share

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.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

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).

Comment

People who like this

0 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image WardPeeters · Dec 08, 2016 at 11:53 PM 0
Share

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");

avatar image

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

Comment

People who like this

0 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bkarakaya01 · Jul 25, 2018 at 01:59 PM 0
Share

Hey man did you try to use "public AnimationClip nameOfYourAnim" instead of "public Animation nameOfYourAnimation".

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

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

I can't edit my animation or play my other animation 0 Answers

How to fix Animation 1 Answer

Why isn't my animation being played? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges