I am making a voxel type game and I’m trying to figure out the best way to store and access the voxel data.
I have a dictionary like so.
public struct Position
{
public int x, y, z;
public Position(int x, int y, int z) { this.x = x; this.y = y; this.z = z; }
public class Check : IEqualityComparer<Position>
{
public bool Equals(Position a, Position b) { return a.x == b.x && a.y == b.y && a.z == b.z; }
public int GetHashCode(Position a) { return a.x ^ a.y ^ a.z; }
}
}
To store each voxel by position but I was thinking.. In order to interact with it I would have to create a new Position each time
if (grid.ContainsKey(new(0,0,0)) { return grid[p]; }
Since I’ll be generating terrain in the millions of voxels I think having to create a new struct position each time would be very bad for garbage collection in unity.
Would using an array be better?
Node[,,] grid = new Node[256,128,256];
grid[0,0,0] = new Node();
grid[0,0,0].type = 23;
Also, what about using a multi dimensional list? Would it be better than an array?
1