Optimal way of checking an area for obstacles

Hi,

I have just joined a Unity project and I have to check an area for a construction system in an RTS.
area

We currently have a grid system.

I want to check whether multiple areas 0.24*0.24 from the mouse position are free to construct the building.

What’s the proper way of doing it?

Hi

If you just want to check if any nodes in those bounds are unwalkable, then you can use:

var grid = AstarPath.active.data.gridGraph;
var nodes = grid.GetNodesInRegion(bounds);
bool anyUnwalkable = false;
foreach (var node in nodes) {
    if (!node.Walkable) anyUnwalkable = true;
}
if (anyUnwalkable) Debug.LogError("This is a bad place to construct a building");
else Debug.Log("This is a good place to construct a building");

You may also be interested in GraphUpdateUtilities - A* Pathfinding Project