So Ive created a hexagonal grid that covers my flat world where each grid point is a hexagon. There are game objects on this flat world that need to register themselves with the grid point they are occupying. Im trying to figure out what is the best way to assign these objects to said grid point.
One thought I had was to have the grid hover over the world. Then each object would cast a ray straight up and detect which grid point is directly over it. Then to use the ray hit information to register with the right point. The drawback is that the world could have thousands of objects all performing a ray cast at the same time, and Im not sure how that would affect performance. Also the grid is just a mathmatical construct and not a gameobject so Im not sure how to test if the ray intersects the interior of a gridpoint.
The next thought was to keep an array containing the gridpoints and have every object iterate through the list to test its points within the bounds of a gridpoint until it finds one. But then you have over a thousand objects iterating through the list at the same time and Im concerned about performance there to.
The optimal solution would have the gridpoints automatically detect all the gameobjects inside of them. But im not sure how to go about this without keeping a list of all the gameobjects and having each gridpoint iterate through that list and testing there origins. Which means Im might have around 150 gridpoints each iterating through a list of thousands all at the same time.
Any thoughts on the optimal method for this?