Unreachable Areas

I am creating a random grid graph by script, which is working fine. But I need to make sure that there are no unreachable nodes in it (isolated from any other nodes). If there are any, I would simply perform the random grid graph generation again. How can I check if there are any unreachable nodes?

Thanks, and Best


You can do something like this after the graph has been scanned:

var graph = AstarPath.active.data.gridGraph;
var allNodes = new List<GraphNode>();
graph.GetNodes(node => {
    if (node.Walkable) allNodes.Add(node);

if (PathUtilities.IsPathPossible(allNodes)) {
    // All nodes are in the same connected component
} else {
    // Some nodes are not reachable from other nodes
1 Like

Hi @aron_granberg

Related to this I want to ask is there a way to discard unreachable areas on Recast Graph ?

For example I have this procedural terrain and sometimes it generate some nodes that not un-reachable.