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 piekiller99 · Oct 13, 2012 at 02:44 AM · null

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

Hello I am trying to make a game and keep getting this error message:

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

GUI_HUD.OnGUI () (at Assets/Scripts_/GUI_HUD.js:23).

And I for one have no idea what it means and my friend and I have trying to figure it out. The code of the GUI_HUD looks like this

 var customSkin:GUISkin;

 var EXPImage:Texture2D;

 var healthpotionImage:Texture2D;

 var manapotionImage:Texture2D;

 

 private var customControls:GUI_CustomControls;

 private var playerInvo:Player_Inventory;

 

 function Awake()

 {

     customControls = FindObjectOfType(GUI_CustomControls);

     playerInvo = FindObjectOfType(Player_Inventory);

 }

 

 function OnGUI()

 {

     if(customSkin)

     {

         GUI.skin = customSkin;

     }

         

     //Inventory Buttons --------------------------------------

     if(customControls.InvoHudButton(Rect(10, Screen.height - 100, 93, 95), playerInvo.GetItemCount(InventoryItem.MANAPOTION), manapotionImage, "Click To Use a Mana Potion"))

     {

         playerInvo.UseItem(InventoryItem.MANAPOTION, 1);

     }

     

     if(customControls.InvoHudButton(Rect(110, Screen.height - 100, 93, 95), playerInvo.GetItemCount(InventoryItem.HEALTHPOTION),healthpotionImage, "Click To Use a Health Potion"))

     {

         playerInvo.UseItem(InventoryItem.HEALTHPOTION, 1);

     }

     

     //Non Usable Inventory Buttona ------------------------------

     customControls.InvoHudButton(Rect(Screen.width - 210, Screen.height - 100, 93, 95), playerInvo.GetItemCount(InventoryItem.EXP), EXPImage, "Amount of EXP");

 }

 

 function Start () {

 

 }



the GUI_CustomControls code looks like this

 function InvoHudButton(screenPos: Rect, numAvailable : int, itemImage: Texture, itemtooltip: String ) : boolean
 {    
         if( GUI.Button(screenPos, GUIContent(itemImage, itemtooltip), "HUD Button") )
         { 
             return true;
         }
         GUI.Label( Rect(screenPos.xMax - 20, screenPos.yMax - 25, 20, 20 ), numAvailable.ToString() );
         
         //display area for tooltips
         GUI.Label( Rect( 20, Screen.height - 130, 500, 100), GUI.tooltip);
 }
 
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MountDoomTeam · Oct 13, 2012 at 03:21 AM

have a look, the error is online 23, it says in the error message. It means that the command you wrote on line 23 is calling an object/component, except that you haven't specified properly the componentthat it supposed to call, the variable is empty basically something to that effect. so you have to figure out a way to specify the variable that it is calling so is properly initialised to a game objects/components/it has found something to execute on.

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 MountDoomTeam · Oct 13, 2012 at 03:26 AM 0
Share

please tell us exactly what is written on line 23 because it's a bit finicky to count without the line numbers. likethat we can see the line in question.

avatar image piekiller99 · Oct 16, 2012 at 01:05 AM 0
Share

if(customControls.InvoHudButton(Rect(10, Screen.height - 100, 93, 95), playerInvo.GetItemCount(InventoryItem.$$anonymous$$ANAPOTION), manapotionImage, "Click To Use a $$anonymous$$ana Potion"))

avatar image MountDoomTeam · Oct 16, 2012 at 06:18 AM 0
Share

use print to debug what is happening, print("is clicked"); in the hudbutton condition to see if it is triggered, print manapotionimage file location, print anything you can to see where all the things are. sorry i dont know GUI yet. the error message is a simple one which sais that unity doesnt recognise the asset you want it to load, because it is not at the asset loaded location you specified. if you call an object that isnt there it will give you null reference, which means your referenced item isnt referenced properly as a variable.

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

10 People are following this question.

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

Related Questions

What does this statement construction mean?: if (null != anim) 1 Answer

NullReferenceException MaskableGraphic.UpdateCull() upon Loading Player Data. 0 Answers

Animation Error "Null reference exception"? 2 Answers

c# 2D array error: need Help! 1 Answer

Resources.Load texture problem 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