Manually updating walkable nodes

    void updateAstar(int x, int y, bool obstacle) {
        AstarPath.active.AddWorkItem(new Pathfinding.AstarWorkItem(ctx => {
            var gg = AstarPath.active.data.gridGraph;
            var nodee = gg.nodes[y * gg.width + x];
            nodee.Walkable = !obstacle;
            gg.CalculateConnections(nodee);
            ctx.QueueFloodFill();
        }));
    }

Hello, I’m trying to update nodes manually one by one using the code above (due to ECS limitations). It works, but the ‘Hierarchical Node’ debug shows something weird. It looks like the nodes haven’t fully updated themselves.

There used to be an obstacle in that square area, then when I remove it, I call the code above to mark the nodes as walkable. But that doesn’t look right. Agents can move onto the newly walkable area, but their path is a little weird. They sometimes move around the former unwalkable area.

Apparently, ctx.QueueFloodFill(); is deprecated because the ‘HierarchicalGraph class’ is supposed to handle ‘pretty much all cases’. However, if I don’t call that function, I get the following:

I also tried calling

gg.GetNodes(node => gg.CalculateConnections((Pathfinding.GridNodeBase)node));

That seemed to properly update everything, however it takes forever to compute. Any suggestions?

Hi

You are only updating the connections for that particular node. That is not enough however. You need to recalculate the connections for that node’s neighbours as well.

    void updateAstar(int x, int y, bool obstacle) {
        AstarPath.active.AddWorkItem(new Pathfinding.AstarWorkItem(ctx => {
            var gg = AstarPath.active.data.gridGraph;
            var nodee = gg.nodes[y * gg.width + x];
            nodee.Walkable = !obstacle;
            gg.CalculateConnectionsForCellAndNeighbours(x, y);
        }));
    }

Ah, you thought about everything eh. I was actually looking for a way to update the cells and its neighbours and what do you know, there’s a built in function for that. Thanks!

1 Like