Seek path over multiple gridgraph's


i have a huge terrain (400SqKm) generated at runtime in tiles with correspondent GridGraph, the pathfinding works great inside each tile however it cant crossover to other tiles, is there anyway to connect the graphs or merge them all ?

PS: The procedural example will not work because its an RTS game with multiple units.



Is only a part of the world loaded at any point in time? Are multiple disjoint regions in the world going to be loaded at the same time?


Hello, yes only certain tiles are being loaded (grids are generated at runtime), there could be some disjoint regions. for exemple if you exploring the map for a new base, eventualy the chunks behind you might get unloaded, but main base chunks are still visible, i dont need it to pathfind through the unloaded chunks, just walking betwen the ones that are loaded is enough.



Okay. This is possible, however linking adjacent grid graphs is not something that is supported out of the box.

If you keep your own internal list of grid graphs you should be able to link the proper nodes together using some code. Something like:

void AddGridGraph(int chunkX, int chunkZ) {
    // z = 0
    for (int x = 0; x < graph.width; x++) {
         var node = graph.GetNode(x, 0);
         var adjacentGraph = GetGraphAtChunk(chunkX, chunkZ-1);
         var adjacentNode = adjacentGraph.GetNode(x, adjacentGraph.depth - 1);
         var cost = (adjacentNode.position - node.position).CostMagnitude;
         node.AddConnection(adjacentNode, cost);
         adjacentNode.AddConnection(node, cost);
    // Similar code for the 4 other edges of the graph

Another approach you could use which might be easier is to use overlapping grid graphs.
So you never actually connect different graphs, but you make sure that a given unit uses the graph which has its center closest to it. Since the graphs are overlapping this will ensure that the unit has at least 25% of the grid’s width of pathable space in any given direction (depending on how much larger than necessary you make the grids).
Also take a look at this tutorial for some info that might be useful: