need help with null reference

hi first time poster, kinda basic at programming lvl, im getting a:

NullReferenceException: Object reference not set to an instance of an object
gridmaker.Start () (at Assets/scripts/gridmaker.js:55)

and i would be tankfull if anybody can help me find the bugger :slight_smile:

both scripts are in the same game object:
pathManager.js

#pragma strict
import System.Collections.Generic; //required for list functions

var gridArray = new List.<Transform>(); 





public function AdGridBlock(a : Transform){

	gridArray.Add(a);
	var _tempLenght = gridArray.Count;
	
	Debug.Log("added: " + a + "array lenght now: " + _tempLenght);
	
}


function Start () {
	
}

function Update () {

}

and gridMaker.js

#pragma strict
// Instantiates a prefab into a grid

// new grid name
var gridName = "newGrid";

// grid block prefab
var prefab : GameObject;

// defines _newObj as a GameObject 
private var _newObj : GameObject;

// create grid at this position
var initPOSX = 0; //depth
var initPOSY = 0; //with
var initPOSZ = 0; //height

var gridX = 5;
var gridY = 5;
var spacing = 2.0;

//temp
private var pathmanager : pathManager;
private var tempName : Transform;


function Start () {
//
// create and define our grid holding object
//
	var _parent = new GameObject (gridName);
	_parent.layer = 9; //select path layer, remove for other purposes
	_parent.transform.position = Vector3(initPOSX, initPOSZ, initPOSY);
//
// create the grid and parent the objects to empty _parent object we just created,
// the grid is created from _parent origin position and naming flows left to right then to the bottom
//
    for (var x = 0; x < gridX; x++) {
        for (var y = 0; y < gridY; y++) {
            var pos = Vector3 (initPOSX - x * spacing, initPOSZ, initPOSY - y * spacing);
            _newObj = Instantiate(prefab, pos, Quaternion.identity);
            _newObj.name = "x" + x + "y" + y;
            //
            var tempName = _newObj.transform; //
            //Debug.Log(_newObj.name + " created at: Y " + _newObj.transform.position.y + " X " + _newObj.transform.position.x);
            // define _newObj as child of _parent
            _newObj.transform.parent = _parent.transform;
            //
            tempName = _parent.gameObject.transform.FindChild(tempName.name);
            
            // testing comunication with pathManager
            
            //var objName = _newObj.gameObject;
            
            Debug.Log("tempName is: " + tempName);
            pathmanager.AdGridBlock(tempName);
            
        }
    }
    Debug.Log("gridArray has: " + pathmanager.gridArray);
}

function Update () {

}

The variable pathmanager has not been initialized. You should add the following line to your Start() function inside “gridMaker.js”:

pathmanager = GetComponent(pathManager);

Tip: It is generally better to name your classes using the convention PathManager to avoid confusion with variables which are usually named using the convention pathManager. This is of personal taste :slight_smile: