• 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 xbit272 · Mar 29, 2011 at 01:19 AM · nullreferenceexception

I have a problem in runtime...

i keep getting this error... does anyone know what it means?

"NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.Dispatch (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, System.Object[] args, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.Dispatch (System.Object target, System.String cacheKeyName, System.Object[] args, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetProperty (System.Object target, System.String name)
UnityScript.Lang.UnityRuntimeServices.GetProperty (System.Object target, System.String name)
shoot.Update () (at Assets/Enemy Soldier/shoot.js:11)"

its when i run this code it says boo.lang.Runtime error, but the code is javasript...

//Based off of MECH WARRIOR hit miss system.

var instantiatedEnemy : GameObject;//object GUI is attached to var enemyInRange : boolean;//range var enemyHealth : GameObject;//the instantiated object (leave blank) var accuracy : int;//the accuracy. var randomNumber : int;//random number enemyInRange = false; function Update () { //shoot if in range if(enemyInRange){ enemyHealth = instantiatedEnemy.GetComponent("Soldier Button GUI").cloneSoldier;//i know this is the problem...// randomNumber = Random.Range(3,18); if((accuracy + randomNumber) > enemyHealth.GetComponent("Ally Health").defence){ enemyHealth.GetComponent("Ally Health").Health -= 5;//and this once that works...// } } }

Comment
Add comment · Show 3
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 Justin Warner · Mar 29, 2011 at 01:31 AM 0
Share

Up top their is a 10101 button, highlight your code/errors, and please push it for us to help you more =). Thanks a lot!

avatar image Justin Warner · Mar 29, 2011 at 01:32 AM 0
Share

Can you tell me what that line of code is supposed to do please?

avatar image Jason B · Mar 29, 2011 at 01:49 AM 0
Share

To me it looks like the problem is you're trying to assign a component to become a gameobject. Which, unless I'm mistaken, cannot be done.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Ray-Pendergraph · Mar 29, 2011 at 11:25 AM

Given:

at Assets/Enemy Soldier/shoot.js:11

I would say that either instantiatedEnemy is null OR there is no component on that called "Soldier Button GUI". I think I would go with the latter, this is presumably the name of a Monobehaviour on the instantiated enemy and it has spaces in it. Normally (as far as I know) components have to adhere to the standard class name conventions. So SoldierButtonGui would be the name of a class you have written and put onto the enemy. When you fix that you likely will get a cast exception because MonoBehaviours are not GameObjects.

Comment
Add comment · 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 xbit272 · Mar 30, 2011 at 10:03 PM 0
Share

ok thanks. the latter was the problem.

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

No one has followed this question yet.

Related Questions

NullReferenceException help 1 Answer

NullReferenceException while trying to access script on object 2 Answers

instantiate prefab object to existing object 1 Answer

NullReferenceException in a GUI Dialog Method 1 Answer

Gameobject.find & my error NullReferenceException: Object reference not set to an instance of an object 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