• 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 Brianf333 · Jul 11, 2012 at 09:10 AM · errorfpsnullreferenceexeption

NullReferenceExeption

Hi, I'm new to unity and programming and I cant find out what this error means: NullReferanceExeption: Object reference not set to an instance of an object Boo.Lang.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory.factory)

NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, 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) PlayerMovementScript.OnTriggerStay (UnityEngine.Collider hitTrigger) (at Assets/Scripts/PlayerMovementScript.js:103) Here is the line of code the error is on: if (current.currentExtraAmmo < current.maxExtraAmmo) Please Help Me.

Comment

People who like this

0 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 whydoidoit · Jul 11, 2012 at 09:12 AM 1
Share

Just one thing - until you have 15 Karma your questions are subject to moderation - please don't keep posting the same question as not all moderating users are able to delete the duplicates. I have deleted the copies on this occasion.

avatar image whydoidoit · Jul 11, 2012 at 09:13 AM 0
Share

current isn't initialized to a value or it has been deleted. Can you post the code that sets up current (by editing your question and indenting it 4 spaces or 1 tab before pasting, or selecting it and clicking the code button after pasting).

1 Reply

· Add your reply
  • Sort: 
avatar image
Wiki

Answer by The_Magical_Kiwi · Jul 11, 2012 at 11:11 AM

You get a null reference exception when your script tries to access a piece of information that isn't set to anything (it is null).

I'm assuming you know what a variable is? Variables normally have default values, for instance:

 //Some pseudo code
 int foo;
 print(foo);

This should print "0" because an integer is 0 by default.

References are a pointer to an object. For instance if you have a 'Bike' class, you can create a reference to it in the same way you declare a variable.

 //something like (again pseudo code)
 int speed = 10;
 //This next line creates the reference 'myBike'.
 //myBike is a reference to the new instance of the Bike we are creating.
 Bike myBike = bike(speed);

For simplicity sake, it isn't too important right now that you know the difference between a reference and a variable, what is important to know is that references don't have default values. If you don't set it to something it remains a reference to nothing, it is null.

If you try to look at or interact with a null reference you will get the error "null reference exception".

 if (current.currentExtraAmmo < current.maxExtraAmmo)

In your case, it would appear that the reference 'current' is null, it hasn't been pointed to an instance of anything. It can't check if extraAmmo is less than maxExtraAmmo because it doesn't know what object to look in.

A very long winded answer I know, but I hope it explains why you got the error and not just how to fix it without you understanding the cause.

Also it is extremely difficult to answer this question without using some simple programming jargon such as object, variable, pseudo code, reference and so on. However a quick google search should be able to explain these concepts much better than I can.

Hope this has helped.

Comment
Sildaekar
Colnire

People who like this

2 Show 0 · 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

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

7 People are following this question.

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

Related Questions

A node in a childnode? 1 Answer

NullReferenceException 1 Answer

I am having a problem with the following script 1 Answer

EGL_BAD_MATCH-Error on Startup (Android) 1 Answer

Why does unity3D crash when starting this script in play mode? 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