- Home /
Why am I getting a null error?
Why am I getting a null error on the last line of this code. I am setting it up in a nested loop of i and j.
Grid is defined as: Private Transform[,] Grid; wall is defined as: Public Transform wall; (although I have also tried this as Gameobject, but Transform works ok)
Transform newCell;
newCell = (Transform)Instantiate(wall, new Vector3(i, j, 0), Quaternion.identity);
newCell.name = string.Format("WALL ({0},0,{1})",i,j);
newCell.parent = transform;
Grid[i, j] = newCell;
Answer by fafase · Feb 06, 2014 at 05:28 PM
private Transform[,] Grid;
will just declare the pointer for a 2D array, you still have to instantiate the locations to be used:
private Transform[,] Grid = new Transform[valueX, valueY];
So basically at the start of the code, after I have declared
Public int width,height;
I should then have the declaration
private Transform[,] Grid = new Transform[width, height];
?? I just tried that as it wont let me as width and height are not static, and this needs t be defined for each maze. So would I have to do something with it when I am trying to assign the newCell to the Grid[,] (after all it is the last line that is failing when I try to add the newcell in to my Grid[,]?
Your answer
Follow this Question
Related Questions
Destroyed Objects causing errors (transform/setdestination) 1 Answer
if ( Transform == null) ?? Empty Transform reference 1 Answer
how can I check if an object is null? 4 Answers
update function problem 2 Answers
MissingReferenceException Help 1 Answer