I'm getting an error message on the following two scripts and I can't figure out why:
And the second script is:
The first is a script called 'interactable.js' to be attached to a number of objects that the player can click on to add to an inventory as well as a list of objects to be deleted when the player next enters that scene, most of which isn't written yet.
The second is a script called 'game.js' attached to an object called 'game' which has another script that will cause it not be destroyed on load and will destroy itself if a previous version of itself exists.
The line I'm getting a null reference exception on is the `game.SendMessage("addNewObject", this.name);`
To be specific, this is the Null Reference Exception:
What's going on?
I got the same problem , the problem is when you attached the 'game' to this atribute 'var game : GameObject' from the unity Inspector , make sure that you selected the right one , select the game from hierarchy , and not from Assets(in case you have a prefab of 'game')
"this.name" this appears to be your problem area. Use gameObject.name, in stead. The "this" keyword returns the component, not the GameObject it's attached to, thus, it returns the name of the class, and not the GameObject.
answered Sep 08 '12 at 09:22 PM