Check that rect area is walkable

Is it possible to check if a rect area is completely walkable?

Sometimes I need to spawn an object, and I must ensure that it spawns on the walkable area and not inside of the walls. Using the classic way to get the nearest node and snap to it works fine for when the object is definitely inside of the wall. But often I just want to spawn the object on a walkable continuous playfield without snapping.

Hi

You can use GridGraph.GetNodesInRegion(bounds) and then iterate through the nodes and check that they are walkable.
See Documentation

1 Like

Has this been updated? This method doesn’t seem to exist now. I’m trying to access the method via GridGraph directly. Is there a qualifier I need to use or something?

It’s still available. Though it’s an instance method, not a static method. So you need something like:

AstarPath.active.gridGraph.GetNodesInRegion(...)

Check the documentation for more info

I was trying to read the docs, didn’t see that it was instanced. The above code doesn’t work, there is no gridGraph member in AstarPath.active for me. I’ll try updating

Oops, sorry. That should be

AstarPath.active.data.gridGraph.GetNodesInRegion(...)

Ah no worries, thanks for the quick reply