GridGraphRules vs TraversalProvider (or using them together)

I have a 400x400 2D tilemap in which walkability can change when walls are built or caves are mined. (Rimworld-like).

Every node has a cost based on what things are on that node (items, vegetation etc). I think using GridGraphRules is a good candidate in my case because this data doesn’t change that often and when it does it only changes for a very few amount of tiles at one time.

Up until now, I was using a custom TraversalProvider for all my pathfinding because of how simple and powerful it is. If a character needs to know if they should go through a door or around, I’d just use a TraversalProvider that checks this in the override CanTraverse method. The TraversalProvider would also fetch the Node cost like so:

public uint GetTraversalCost(Path path, GraphNode node)
{
    return (uint)NodeManager.NodeDataAt(Vector3Int.FloorToInt((Vector3)node.position)).NodeCost;
}

However, if I understand correctly, using TraversalProvider is quite slow because all of this data needs to be checked for every single examined node. I assume pre-calculating all of the Node costs with a GridGraphRule would be much faster. (Please correct me if I’m wrong!)

My questions are:

  1. Does a GridGraphRule always update the entire map, or is it possible to update only a single tile? How can you switch between those two modes? (Entire map on world generation, single tile on runtime)

  2. How does a GridGraphRule interact with TraversalProvider? What if a character needs to use a custom TraversalProvider to do some custom checks for the CanTraverse method (like if he can go through a door or not), but wants to re-use all of the pre-calculated node costs from the GridGraphRule? How can I combine these two things to achieve control and efficiency?

  3. Is there even a point in updating the graph with gridGraph.GetNode.IsWalkable and gridGraph.CalculateConnectionsForCellAndNeighbours if using a TraversalProvider, since a TraversalProvider has to calculate walkability and cost for each node on each new pathfinding request anyway?

For 1. a graph rule only applies to the area specified in an update. I don’t know the answer to 2.

  1. It is possible to use it to update only a small region (using e.g. AstarPath.active.UpdateGraphs(bounds)).
  2. In your GridGraphRule you can assign a static penalty to the nodes, or assign a tag to the nodes. Your ITraversalProvider can then check for those.
  3. Not really. The ITraversalProvider is layered on top of previous checks. So you don’t need to update the graph to use it.