Accessing a global variable's referenced object's variable

I realize that the phrasing of the question is probably a bit confusing, but I couldnt think of better wording.

I know how to access an object’s variables through another object, but I’m running into a problem when trying to get the variable of another object, which is set as a global variable, and get that object’s variable.

What I’m trying to do is take firstClickedNode from the global variables script (see below) and pull a variable off of its instance. So pulling from the code below, I tried


This gives an error saying:
“Object reference not set to instance of object”

I’ve also tried using a GetOptions function and running the function instead of the variable directly but that gave similar issues.

Is there something you have to do differently when referencing an object that is set in a variable, in particular if it is global? Logically this should work to me…

So I have the GlobalVariables.js script:

static var nodeSelected = false;
static var firstClickedNode : GameObject;
static var secondClickedNode : GameObject;

And my script for the game:

var globalVar : GlobalVariables;
var globalGameObj : GameObject;

var isGoalNode : boolean;
var isBlue : boolean;
var isGreen : boolean;
var isRed : boolean;
var isTransfer1 : boolean;
var isTransfer2 : boolean;
var isTransfer3 : boolean;

var blueMat : Material;
var greenMat : Material;
var redMat : Material;
var trans1Mat : Material;
var trans2Mat : Material;
var trans3Mat : Material;

var wasClicked = false;

var option1 : GameObject;
var option2 : GameObject;
var option3 : GameObject;

var lrStartPosition : Vector3;
var lrEndPosition : Vector3;

function Awake(){
	//disable the halo by default
	gameObject.GetComponent("Halo").enabled = false;
	//Check node settings and set up materials and properties
	if(isGoalNode == true){
		if(isBlue == true){
			renderer.material = blueMat;
		else if(isGreen == true){
			renderer.material = greenMat;
		else if(isRed == true){
			renderer.material = redMat;
		if(isTransfer1 == true){
			renderer.material = trans1Mat;
		else if (isTransfer2 == true){
			renderer.material = trans2Mat;
		else if(isTransfer3 == true){
			renderer.material = trans3Mat;

//Highlight for when object is selected
function Highlight(){
	globalVar.nodeSelected = true;
	gameObject.GetComponent("Halo").enabled = true;

function Unhighlight(){
	gameObject.GetComponent("Halo").enabled = false;
	globalVar.nodeSelected = false;
	wasClicked = false;

//Set Global Variable
function SetTargetNode(){
	globalVar.secondClickedNode = this.gameObject;

function GetOptions(){
	return option1;

function OnMouseDown(){
	if(globalVar.nodeSelected == false){
		if(wasClicked == false){
			globalVar.firstClickedNode = this.gameObject;
			wasClicked = true;
	else if(globalVar.nodeSelected == true){
		if(wasClicked == true){
			globalVar.firstClickedNode = null;
		else if(wasClicked == false){
			print("option 1 is: " + globalVar.firstClickedNode.option1);
			if(globalVar.secondClickedNode == globalVar.firstClickedNode.option1){	
				globalVar.secondClickedNode = null;

Just access this in your code:


The point of it being global is that you don’t need to create an instance of it.