Hi,
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?
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
}