Init code goes to Null unknow reason

Hello Unity Community,

This is very basic question and i feel ashamed to ask this, but i feel i’m missing something.
I’m simply initializing my grid on Start(), however when i try to acces it from addBuilding() it returns null.

Start() is the only place where the grid is assigned. It seems so simpel, but because it is so
simple quite hard.

public int rectangles_x, rectangles_z;
private GameObject[,] grid
void Start () {
    grid = new GameObject[rectangles_z , rectangles_x];
    // A debug log returns the right 2D array
}

public void addBuilding(int x, int z, GameObject obj) {
   Debug.Log (this.grid); // This returns Null
   //grid [z, x] = obj; //This part gives "NullReferenceException" because grid == null
}

Hopefully anyone can help me.

With kind regards,
Nkmol

Its returning null because you have just supply the dimension and by default it will get initialize to “null” and since its not pointing to any objects right now, which means its value is null.

it was my Script Excution Order. Apperently Start() wasn’t called first. I feel so stupid ^^ Thanks for the help all!