Manually update recast graph nodes

Hi! When I generate recast graph, aside from floor, it also builds graph on top of roof. So I thought, that I could easily get all nodes, check which one has large Y value and remove it.

GetNodes() seems not to be returning node array. May you give me any hints on how should I best approach this task? Is it generally safe to remove nodes if I get their array?

Hi

What you can do instead is mark your roof so that it doesn’t generate a navmesh on top of it. Simply attach a RecastMeshObj to it. See http://arongranberg.com/astar/docs/class_pathfinding_1_1_recast_mesh_obj.php#a5008f5aaa9ef50b1510e309dce9205d7

Alternative

You cannot remove any nodes from the graph, but you can mark them as unwalkable. So when you iterate over them using GetNodes, you could set the Walkable field to false when necessary.

I recommend that you wrap it in a RegisterSafeUpdate call to make sure that pathfinding is not running at the same time as you update the graphs.

AstarPath.RegisterSafeUpdate (() => {
    var graph = AstarPath.active.astarData.recastGraph;
    graph.GetNodes ((node) => {
        // Do stuff
        return true;
    });
    
    // Necessary if you have updated the walkable flag to make sure that pathfinding still works
    AstarPath.active.FloodFill ();
 });

Thank you! My roof and floor are within same object, that is why I am facing the problem. But second solution is perfect, setting unwalkable is very similar to deletion anyway.

1 Like