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 Ian-McCleary · Apr 19, 2014 at 08:55 PM · javascriptnullreferenceexceptionscript error

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

You would think that by the title that the error is extremely simple and easy to fix but no matter what i do i cant seem to get it to go away! The full error is

NullReferenceException: Object reference not set to an instance of an object Inventory.OnGUI () (at Assets/Script/InventorySystem/Inventory.js:84)

I am using pictures for a part of my inventory and for some reason it says that it cant identify the picture...or at least thats what i think. My script and pictures of the property inspector are below.

As you can see i named the image i would like to use correctly (See script below image)

alt text

Look to line 84 for when the error starts and then to line 3 for the variable for invBackDrop

 import System.Collections.Generic;
     //backdrops
     private var _invBackDrop : Texture2D;
     private var _equipmentBackDrop : Texture2D;
     //backdrops end
     
     //window Details
     private var _windowPosition : Vector2 = Vector2(0,0);
     private var _windowSize : Vector2 = Vector2(Screen.width, Screen.height);
     private var _windowRect : Rect = new Rect(_windowPosition.x, _windowPosition.y, _windowSize.x, _windowSize.y);
     //Window Detials End
     
     
     //GameObjects
     private var _player : GameObject;
     private var _gameManager : GameObject;
     //GameObjects End
     
     //Script Components
     private var _charMotor : FPSWalkerEnhanced;
     private var _items : Items;
     private var _equipmentManager : EquipmentManager;
     //script Components End
     
     //Main Inventory List
     var mainInventoryList : List.<ItemHandler> = new List.<ItemHandler>();
     
     //this is for dispalying the inventory/equipment screens
     private var _display : boolean = true;
     
     //this will be true when you click th ebutton that says equipment screen.
     private var _displayEquipScreen : boolean = false;
     
     //be true when you click the button that says inventory
     private var _displayInventoryScreen : boolean = true;
     
     
 
     function Start () {
     
         //Locks and hides the cursor
         Screen.lockCursor = true;
         Screen.showCursor = false;
         
         //backdrops
         _invBackDrop = Resources.Load("Backgrounds/InventoryBackground", Texture2D);
         _equipmentBackDrop = Resources.Load("Backgrounds/EquipmentBackground", Texture2D);
         //backdrops End
         
         //Finding GameObjects
         _player = GameObject.FindGameObjectWithTag("Player");
         _gameManager = GameObject.FindGameObjectWithTag("GameManager");
         //Find GameObjects End
         
         //Find the Components
         _charMotor = _player.GetComponent(FPSWalkerEnhanced);
         _items = _gameManager.GetComponent(Items);
         _equipmentManager = _gameManager.GetComponent(EquipmentManager);
         //Finding the components end
         
         
     }
 
     function Update () {
         //this will make it so when you press Tab it will open the inventory and sisables character functions.
         if(Input.GetKeyDown(KeyCode.Tab) && !_display) {
             _display = true;
             Screen.lockCursor = false;
             Screen.showCursor = true;
             _charMotor.enabled = false;
             
         } else if(Input.GetKeyDown(KeyCode.Tab) && _display) {
             _display = false;
             Screen.lockCursor = true;
             Screen.showCursor = false;
             _charMotor.enabled = true;
         }
     }
 
     //this will handle the displaying of our buttons for our items
     function OnGUI() {
         if(_display) {
             if(_displayInventoryScreen)  {
                 GUI.DrawTexture(_windowRect, _invBackDrop, ScaleMode.StrechToFill);
             }
         }
     }
2014-04-19_1349.png (37.6 kB)
Comment
Add comment · Show 1
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 Kieran Chandler · Apr 19, 2014 at 09:10 PM 0
Share

This may sound stupid but are you 100% sure you have spelt the path right

1 Reply

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

Answer by Ian-McCleary · Apr 19, 2014 at 09:06 PM

It appears that i spelled stretch with only one t... sigh

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

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

22 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

im having a problem lerping text color between 2 color 1 Answer

Null Reference Exception confusion 3 Answers

Split() into a fixed length array? 1 Answer

Why ExecuteInEditMode Always Causes NullReferenceException Errors Even In Clamping!! 2 Answers

How can I stop getting Null Reference Exception? 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