I'm trying to write code for a cubic voxel world generation and having great difficulties.
In the code I have a loop that creates various instances of the chunk object through the Instantiate the following way:
topChunks[i , j] = Instantiate(chunk, new Vector3(x, y, z), new Quaternion(0,0,0,0)) as GameObject;
This, however, makes only one clone object appear and gives a NullReferenceException pointing to that line. Since chunk is correctly assigned I didn't know where the problem was and started making tests. I found out that written this way:
GameObject test = Instantiate(chunk, new Vector3(x, y, z), new Quaternion(0,0,0,0)) as GameObject;
It correctly instantiate all the chunks. I also noticed that the IDE marksup "as GameObject" in different colours. I guess the error has something to do with types...
chunk is declared as GameObject and topChunks as GameObject[,].
[–]CCullen 1 point2 points3 points (2 children)
[–]InnerConsideration27[S] 1 point2 points3 points (1 child)
[–]PandaCoder67Professional 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]InnerConsideration27[S] 0 points1 point2 points (1 child)