- Home /
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)
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);
}
}
}
This may sound stupid but are you 100% sure you have spelt the path right
Answer by Ian-McCleary · Apr 19, 2014 at 09:06 PM
It appears that i spelled stretch with only one t... sigh