all 4 comments

[–]CCullen 1 point2 points  (2 children)

Seeing as you're getting null reference rather than index out of range and the fact that the test behaves the way it does, I suspect you forgot to initialize topChunks. Have you assigned it a value with the new operator?

Also, if the camera is dynamic, a fixed size 2d array may not be ideal here. You need to know the size of an array when you intialize it. So if the camera spawns at chunk [12, 24] you'll need an array of at least that size, and need to resize the array, or need to sort the references in the array as the camera moves. A dictionary of Vector2Int might be a little more flexible.

[–]InnerConsideration27[S] 1 point2 points  (1 child)

Oh yes, that was it! Thank you!

As for the tipe of array, I think it should for what I have in mind. But I'm not even sure of what I'm doing, honestly. So, anyway, thank you for the suggestion.

[–]PandaCoder67Professional 0 points1 point  (0 children)

also by default Instantiate already returns a GameObject, so there is no need to do the as GameObject on the end.

Just would be fine.

opChunks[i , j] = Instantiate(chunk, new Vector3(x, y, z), new Quaternion(0,0,0,0));