- Home /
Javascript Endless 3D Array
Hello all,
I have been working on my own voxel engine recently and it is going well, however I am having issues with storage in 3d or 2d arrays. Ideally, I would have an endless three dimensional array to store the chunks that I have created for runtime, but as far as I know, you cannot resize a multidimensional array. My question is: Is this true? If so, is there a better way around this? If not, how would you declare it? I seem to only be able to make multidimensional arrays by declaring size, such as:
var cubeArray : GameObject[,,] = new GameObject[chunkSize, chunkSize, chunkSize];
Thanks in advance for any help!
-Doug
Um endless - no matter how you do that - you will run out of memory faster than you think ;)
Were you intending to stream data to a disk or something?
You really need to write a function to map the world coordinate to the storage system rather than relying on arrays. Arrays like this will probably contain vast amounts of wasted space.
Next up - you probably can't do what you want with GameObjects, your best bet would be dynamically creating cubes in a mesh by modifying vertices and also trying to simplify the actual world compared to the representation (so it might be that the game has 4 cubes making a bigger cube, but while that condition persists you want to graphics hardware to draw just one cube).
Ah, I mean just for holding them during the game. Also, I have my cubes all drawing in depending what faces are visible, made of tris and vertices manually. Thanks for the tips though.
Your answer
![](https://koobas.hobune.stream/wayback/20220613092035im_/https://answers.unity.com/themes/thub/images/avi.jpg)