Object reference not set

Now this is a strange one, I’ve run into this error even though to my mind I’m not doing anything wrong. I’m not for instance getting any syntax errors in my IDE when I write the code.

The error is:
NullReferenceException: Object reference not set to an instance of an object
Model.InitActorRelatedModels (Int32 x, Int32 y, System.String name) (at Assets/Model.cs:42)
Grid.CreateActorUnit () (at Assets/Grid.cs:78)
Grid.Awake () (at Assets/Grid.cs:33)

	public void CreateActorUnit(){
		GameObject act = (GameObject)Instantiate(actorPrefab, new Vector3(1.513628F, 0.0F, 0.4837152F), Quaternion.identity);
		act.renderer.material.color = new Color(2.55F, 0.21F, 0.0F);
		actorUnits [0] = act;

		model.InitActorRelatedModels (1, 1, "hero");  //->code starts here
	}

   public void InitActorRelatedModels(int x, int y, string name){
		gmodel.InitGridModel (x, y);
		actors.ChangeData (x, y, name);
	}


	public void InitGridModel(int x, int y){
		gridModel [x, y] = 1;
	}

Any help would be greatly appreciated.

Hey guys, I just thought I’d answer my own question just in case someone else out there finds this useful.

In the three scripts that I had created I was doing startup code in the Awake() functions in each of them. However, Unity executes each Awake() in an arbitrary order (I put debug statements in each to find this out) This means you can potentially cause errors if one Awake() function MUST logically be executed before another Awake() function. This is what happened to me, one Awake() function was initializing variables that another was also trying to access.

To fix this, I got rid of all the Awake() Functions in the scripts and instead changed them to normal functions. I then had another Script (that I called Init_Order) that sequentially executed each of the old Awake() function code in the order that I wanted.