I tested and it’s true, we can’t retain reference of a multidimensional array in C#.
public GameObject[,] tileMap = new GameObject[20,20];
All members of tileMap will be null after quitting Play Mode. (For more detailed explanation, check my post)
Are developers aware of this situation? Is any fix planned? Or could at least inform this somewhere in the documentation to avoid losing a few hours thinking why the reference becomes null?
I would probably choose to create a grid class as a workaround, but I doubt those would be my variables.
I’d more likely make it a single array, but have math to pull the correct references when using it like a 2 dimensional array. With a little more work, it could probably work with N dimensions as well.
Yeah, workarounds are no problem, but my question was if developers are aware of the situation. But thanks for the alternatives! I personally use the single dimension one, I leave the math for someone interested:
// x, y: 2D array positions you want to access
// width: columns of the 2D array
private int From2Dto1D(byte x, byte y, int width) {
return width * y + x;
}