Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Slim · Feb 17, 2010 at 03:17 PM · animationnull

Animation Error "Null reference exception"?

I am building a FPS (not the tutorial) and I built a series of animations for a gun model using Maya (a .mb file). I have imported the animations, and written a basic script that runs the bolt slide animation when you click the mouse (and fire the weapon) here is the script:

function Update ()
{
    if(Input.GetButtonDown("Fire1"))
    {   
        animation["Element 0"].wrapMode = WrapMode.Once;
        animation.Stop();
    }
}

however, when I run this script, I get a "Null reference exception" message in the debug window, what is the error?

Thanks

Comment
Add comment · Show 2
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 jashan · Feb 17, 2010 at 03:53 PM 0
Share

Which line exactly are you getting the NullReferenceException on?

avatar image Slim · Feb 17, 2010 at 05:38 PM 0
Share

Line 5: animation["Element 0"].wrap$$anonymous$$ode = Wrap$$anonymous$$ode.Once;

2 Replies

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

Answer by Slim · Feb 18, 2010 at 08:41 PM

Wow, I just used the animation.Play command and it works fine, case solved. Now, I wonder what the difference between wrapMode and play is...

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
2

Answer by jashan · Feb 17, 2010 at 03:53 PM

Most likely there is no animation by the name of "Element 0". Or, the game object that you have attached this script to doesn't have an animation component attached to it at all.

Comment
Add comment · Show 4 · 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 Slim · Feb 17, 2010 at 05:08 PM 0
Share

Well, "element 0" is the first element of the animation component of gameObject $$anonymous$$1.Reload (my weapon) $$anonymous$$1.Reload is also the true name of the animation...

avatar image jashan · Feb 18, 2010 at 08:56 AM 0
Share

"element 0" or "Element 0" - in your code, you have "Element 0" (upper-case E), and if it's actually called "element 0" (lower-case e) that won't work as keys in dictionaries are case-sensitive. So that might be it. I'm not perfectly sure I understand you correctly, though - if the name of the animation is "$$anonymous$$1.Reload", it would have to be animation[$$anonymous$$1.Reload"] ins$$anonymous$$d. You should also be able to access the animation via animation[0] though (that would be the first animation component).

avatar image Slim · Feb 18, 2010 at 08:29 PM 0
Share

I do not believe it is the name that is the issue, I simplified the game quite a bit and made it so its supposed to only do one thing when the mouse is clicked, run "$$anonymous$$1.Reload" But even with this simple program, while I don't get any error message, it simply won't play the animation. When I check the play automatically box in the animation component of the m1 gameObject, the animation plays, which proves that the animation IS there...

avatar image Slim · Feb 18, 2010 at 08:30 PM 0
Share

*play on start, my bad.

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Animation script with is.grounded help 0 Answers

change animation name in inspector 2 Answers

Animation component in Unity 4.3 doesn't work? 2 Answers

Character controller problem? 2 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