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 Tyler Alvis · Feb 05, 2011 at 04:00 AM · nullreferenceexception

How can i fix this weird error

I have this script so when i click space the character whould reach up and take a sword off his back, and when i click space i get this wierd error:

NullReferenceException: Object reference not set to an instance of an object walker.Update () (at Assets/my scripts/walker.js:22)

this is my script:

if(Input.GetButtonDown("Jump")) { var animationComp : Animation[] = gameObject.GetComponentsInChildren(Animation) as Animation[]; for (var animComp : Animation in animationComp) { animComp.Play("grab sword");

     }
 }

whats wrong?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by andrew 3 · Feb 05, 2011 at 04:09 AM

my first question dose he at least take the sword out or dose it just give you the error right of the bat i would say if he is not taking out the sword at all it is most likely since this is java script that java script dose not know it as jump it knows it as space bar try this and tell me your result i hope this helps.

Comment
Add comment · Show 3 · 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 Tyler Alvis · Feb 05, 2011 at 04:37 AM 0
Share

when i press space (with my script, it works) i get the error, not right off the bat

avatar image andrew 3 · Feb 05, 2011 at 03:42 PM 0
Share

then i wold say tat when he takes out the sword he dose not no how to put his sword away try anding after the grab sword to say if(Input.GetButtonDown("Jump")) { Animation[] animationComp = gameObject.GetComponentsInChildren(Animation) as Animation[];
foreach (Animation animComp in animationComp) {
animComp.Play("put back sword");

     }

} try this and see what happens

avatar image Tyler Alvis · Feb 05, 2011 at 07:15 PM 0
Share

how would that help because if it didn't know how to put it back, then there would be no way to put it back but he would still take it out. $$anonymous$$y problem is when i click space i get an error and he does nothing.

avatar image
0

Answer by fireDude67 · Feb 05, 2011 at 04:11 AM

Your codes says var it should be this:

if(Input.GetButtonDown("Jump"))
    {
        var animationComp : Animation[] = gameObject.GetComponentsInChildren(Animation);
        for (animComp in animationComp) 
        {         
            animComp.Play("grab sword");
        }
}

For a complete list of differences from C# to JS, see this post: http://answers.unity3d.com/questions/5507/what-are-the-syntax-differences-in-c-and-javascript

Edit: Oops, Don't Regularly use JavaScript, so I forgot to add var keyword... :)

Comment
Add comment · Show 9 · 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 Tyler Alvis · Feb 05, 2011 at 04:32 AM 0
Share

i got these errors:Assets/my scripts/walker.js(21,26): UCE0001: ';' expected. Insert a semicolon at the end.

Assets/my scripts/walker.js(21,28): UCE0001: ';' expected. Insert a semicolon at the end.

Assets/my scripts/walker.js(22,36): BCE0044: expecting ), found 'animComp'.

Assets/my scripts/walker.js(22,61): BCE0043: Unexpected token: ).

Assets/my scripts/walker.js(24,52): BCE0044: expecting :, found ';'.

avatar image fireDude67 · Feb 06, 2011 at 01:56 AM 0
Share

it should be C# not JS

avatar image Tyler Alvis · Feb 07, 2011 at 04:20 AM 0
Share

Could you give it to me in JS because i Have a lot more to that script i just didn't post it because it did not have anything do do with this

avatar image fireDude67 · Feb 08, 2011 at 01:27 AM 0
Share

Thanks for not posting the irrevelant part

avatar image Tyler Alvis · Feb 10, 2011 at 02:15 AM 0
Share

i got these errors:

ArgumentException: You are not allowed to call get_gameObject when declaring a variable. $$anonymous$$ove it to the line after without a variable declaration. Don't use this function in the constructor or field initializers, ins$$anonymous$$d move initialization code to the Awake or Start function. walker..ctor () (at Assets/my scripts/walker.js:5)

Assets/my scripts/walker.js(24,31):BCE0043: Unexpected token: :.

Assets/my scripts/walker.js(24,32): UCE0001:';' expected. Insert a semicolon at the end.

/my scripts/walker.js(24,42): UCE0001:';' expected. Insert a semicolon at the end.

Show more comments

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

NullReferenceException: Object reference not set to an instance of an object. 2 Answers

Instantiate giving a NullReferenceError 1 Answer

NullReferenceException: Object reference not set to an instance of an object 2 Answers

MoveTowards doesn't work after changing tag. 2 Answers

NullPointerException while changing a variable from one script in another 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