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:
-
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) -
How does a
GridGraphRule
interact withTraversalProvider
? What if a character needs to use a customTraversalProvider
to do some custom checks for theCanTraverse
method (like if he can go through a door or not), but wants to re-use all of the pre-calculated node costs from theGridGraphRule
? How can I combine these two things to achieve control and efficiency? -
Is there even a point in updating the graph with
gridGraph.GetNode.IsWalkable
andgridGraph.CalculateConnectionsForCellAndNeighbours
if using aTraversalProvider
, since aTraversalProvider
has to calculate walkability and cost for each node on each new pathfinding request anyway?