- Home /
Object reference not set... but... it is?
So I'm getting an error saying that my GameObject "item" isn't set to an instance of an object. I don't understand what the problem is. This is the line with the error (I'm trying to print the item's name as a test):
public void displayItemDescription(float width, float height) {
Debug.Log(item.name); //error highlighted here, ignore other stuff for this case.
GUI.Box(new Rect(0, 50f + (height - 250), width, height), "" + itemDesc);
}
The GameObject item is set to public so I can see when the item changes depending on what button is being hovered over. The changing of the item variable happens in this code:
GameObject goItem = (GameObject) item;
if(inButtonArea(px,py,75f,75f)) { //a function for checking if hovering.
player.GetComponent<CraftMenu>().item = goItem; //set current object to item in other script
}
Comment
If you change Debug.Log(item.name);
to Debug.Log(item);
it should output 'null' in the console. (And your error will probably jump to the next time the code tries to access 'item.') Null means there is no actual GameObject (reference) in the item variable.
That's the problem. Even if I put an object in that variable it still gives me that error.