Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by Quadriladder · Sep 02, 2014 at 10:48 AM · errorannoyinghard

Unity animations never play, only pause game?!!?!

Hi. Im having this REALLY annoying problem with my unity engine. Ive done some animations, and no matter what way i try to activate them, it never works. The script comes up with no errors, it just pauses the game debug thing. If i unpause it, its fine!. SO ANNOYING!. Ive created new projects and they do not work either. I've tried all methods that are online, and every step of you tube vids and i just cannot get these animations to activate!!!! When i build and run, it shows the error "Object reference not set to an instance of the object" and doesn't pause the game, it just continued as if it never happened? This is basically the code i use each time below. I use the variable of the animation to change things, even without it it doesn't work. Its currently really limiting my projects! Any help would be greatly appreciated! Thanks

var anim : AnimationClip;

function Update () {

if( Input.GetKeyDown("r")){

animation.Play("anim"); }

}

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by kacyesp · Sep 02, 2014 at 12:00 PM

Make sure you attach the animation to the game object in the inspector (Add Component -> Miscellaneous -> Animation). Once you've attached the Animation component, increase the size to however many animations you have. Then drag your Animation clips into the empty slots. I posted a screenshot below of what the Animation Component should look like.

 function Update () {
     
     if( Input.GetKeyDown("r"))
         animation.Play("nameOfAnimation"); 
     
 }


alt text

I increased this Animation component to have a size of 4, meaning I can add 3 more animations to it since I've already added 1.


animationcomponent.png (11.4 kB)
Comment
Add comment · 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
0

Answer by Gizmoi · Sep 02, 2014 at 11:06 AM

Sounds like 'animation' isn't being set properly, which is causing a null reference when you try to access it.

I imagine you also have the 'Error Pause' option checked on the debug console, which will cause the Editor to pause when an exception is thrown.

You should make sure that animation is assigned correctly. I suspect you actually meant to use the declared member variable 'anim'. If this is so then your code should be:

 var anim : AnimationClip;
 
 function Update()
 {
   if (Input.GetKeyDown("r"))
   {
     if (animation != null)
     {
       animation.Play("anim");
     }
   }
 }
Comment
Add comment · Show 2 · 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 Quadriladder · Sep 02, 2014 at 11:12 AM 0
Share

Hello. I tired that but it did not work, however that doesnt mean that it isnt progress. Now when i build and run it i get the error "$$anonymous$$issing$$anonymous$$ethodExeption.UnityEngine.AnimationClip.Play" $$anonymous$$aybe this is a easier problem to solve? Thanks

avatar image Gizmoi · Sep 02, 2014 at 12:07 PM 0
Share

Ah yes, I was mistaken. I didn't realise your original code was accessing the 'animation' property from $$anonymous$$onoBehaviour.

Your original code was correct. However you should add an Animation component to the object that has this script on it.

You should probably also add a null reference check to stop the error happening. I'll edit the answer to show this.

avatar image
0

Answer by Quadriladder · Sep 02, 2014 at 12:42 PM

Thankyou so much for the great responses. I ended up adding the animations like above, then removing the variable and works great. Thanks everyone!

Comment
Add comment · Show 2 · 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 GluedBrain · Sep 03, 2014 at 01:16 AM 1
Share

The procedure is you got to mark the respond which helped you the most!

avatar image kacyesp · Sep 03, 2014 at 01:21 AM 0
Share

You should upvote anything that was helpful to you, whether it was actual answers or comments. And you should mark whichever answer helped you the most as the accepted answer.

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Method Not Found: 'Network.InitalizeServer' 0 Answers

Visual studio says no issues found even though there are errors. 1 Answer

I am now having an "internal compiler error" that sometimes appears as a warning and sometimes an error. It won't let me fix it either... 1 Answer

GetThreadContext Failed 0 Answers

No appropriate version of 'UnityEngine.AudioSource.Play' for the argument list '(System.Type)' was found. 1 Answer


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