- Home /
What is the reason for this NullReferenceException?
None of my other Objects seem to be able to reference the script ItemManager, every time I call for a static variable from it, it returns null.
World -
Player -
Here is the first (of many) places I get the error:
NullReferenceException: Object reference not set to an instance of an object
Inventory.Start () (at Assets/Scripts/Player/Inventory.cs:58
Line58: ItemSlot temp = new ItemSlot(ItemManager.EMPTY.ShallowCopy());
I think it has to do with the static variable EMPTY, however I believe I have it setup correctly:
public static Item EMPTY;
public static Item STONE;
public static Item GRASS;
public static Item BRICK;
//************************************
// Use this for initialization
void Start () {
Debug.Log ("Initalized");
guiCon = gameObject.GetComponent ("GUIController") as GUIController;
soundMan = gameObject.GetComponent ("SoundManager") as SoundManager;
// *** Set new ***
// *** Initialize Item ***
EMPTY = new Item("", 0 , 64, new Rect(0.25f,0.75f, 0.25f,0.25f), itemIcons, Item.ItemType.Empty,"DefaultItem");
// MORE CODE AFTER...
I can eli$$anonymous$$ate most the null reference exceptions to the Item$$anonymous$$anager script by setting script execution order, but it doesn't fix them all so I think there is some other issue.
Try moving the E$$anonymous$$PTY = ... stuff into Awake()
Answer by Zexanima · Mar 31, 2014 at 04:58 AM
I saved, reopened Unity, and it was suddenly working. I didn't even change anything. Don't know what was wrong.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Audio Play Once 2 Answers
How do you position an object relative to the camera? 0 Answers
Does Scripting Jump exist? (How To use/write goto) 3 Answers
Destroy only selected object 1 Answer