Best way to keep track of objects on a 3D Grid?

I’m looking for a good way to keep track of objects on a 3d grid. For example, I want to query a point at say: (0,0,0) and find out if there are objects on any of its 4 “corner” points on the X/Z grid plane. (These would be (1,0,1) ; (1,0,-1); (-1,0,1); and (-1,0,-1)).

Note these would be custom grid coordinates, not transform.position values per se.

I was thinking a good way to do this might be a multidemensional transform array of some sort, but since array’s can’t take negative values I probably can’t store the relevant grid-position data there.

Any help to get me started is appreciated!

You should use multi-dimensional array. You can’t access negative positions, which is the correct behaviour, but you could implement a function that takes a Vector3 as input, find the appropriate array indices and return the object at that position in the array.

If you have the center (or one of the corner) of your grid, the column/row count and the width/height of each “square” in your grid, it is relatively easy to do this.

I’ve actually found a solution using:

Dictionary , which was pretty easy once I got some sleep :slight_smile:

Thank you though!