NullReferenceArray with GameObject

public GameObject[,] blocks;

void Start() {
float Z = -128;
float Y = 0;
for ( float X = -128; X < 129 ; X ++ )
{
GameObject newBrick = new GameObject(“Voxel”);
newBrick.transform.Translate( new Vector3(X,Y,Z) );
newBrick.layer = 8;
blocks[(int)X,(int)Y,(int)Z];

if ( X == 64 )
{
X = -64;
Z += 1;
}

if ( Z == 64 )
{
Z = -64;
Y += 1;
X = -64;
}

}
}

Why does it keep giving me “NullReferenceError” ?

First of all, please use code comment - it makes it easier to read and understand.
Second, where does the error come from? (Line of code that the compiler marks)
Third, what is this “blocks[(int)X,(int)Y,(int)Z];” ?
You refer to an object that may not even exist, and you don’t even do anything with it!
Did you even initialize that array? It is not a list, you can’t just dynamically add an object - you have to create a new array with a set number of values.
blocks = new GameObject[maxX,maxY,maxZ], and only then can you add something inside one of the initialized cells.

If it was a single dimensional array you don’t have to declare the size (in most cases you still should) but in multidimensional arrays like yours you do. You can also use a variable to set the max when you initialise it. So for example with MrPriest’s example “maxX” and the others could be seperate variables.

I think you wanted:
blocks[(int)X,(int)Y,(int)Z] = newbrick;
otherwise you are asking for that spot in the array and then ignoring it.

the (int) I’m guessing were just to cast the floats as ints

I’m not sure about voxels so I can’t say if that is the correct way of generating one of those.

Sorry about that, I get the null reference error when I try to do blocks[(int)X,(int)Y,(int)Z] = newBrick;

So have you got this working?

If not try:
public GameObject[,] blocks = new GameObjects[258, 65, 192];

Any reason you start Z at -128 instead of -64? If so that is OK if not then you could change Z and save a bit of memory.