OnMouseDown() NullReferenceException

I’m getting an error message on the following two scripts and I can’t figure out why:

#pragma strict

var game : GameObject;

function Start()
{
	game = GameObject.Find("game");
}

function OnMouseDown()
{
	game.SendMessage("addNewObject", this.name);
	Destroy(gameObject);
}

And the second script is:

var objectList : String[] = new String[10];
var inventoryList : String[] = new String[10];
var listLength : int = -1;

function addNewObject(object : String)
{
	objectList[++listLength] = object;
	inventoryList[listLength] = object;
}

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:

NullReferenceException
UnityEngine.GameObject.SendMessage (System.String methodName, System.Object value) (at C:/BuildAgent/work/d9c061b1c154f5ae/Runtime/ExportGenerated/Editor/UnityEngineGameObject.cs:257)
interactible.OnMouseDown () (at Assets/Scripts/interactible.js:32)
UnityEngine.SendMouseEvents:DoSendMouseEvents()

What’s going on?

“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.

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’)