Infinite modifiable world, multiplayer, multiple graphs

Hello,

I just bough this amazing framework to improve the AI part of our project
We have the following requirements :

  • An “infinite” world, with procedurally generated chunks, and chunk loading only around connected players
  • A multiplayer game, so several players, potentially far from each other
  • A modifiable world (terrain modification, constructions)
  • Several types of creature with differents characteristics (radius, height, capacity to swim, …)

Until today, it’s working with unity standard NavMesh, with a mecanism that :

  • dynamically build a navmesh for each chunk, when a chunk and its neighbors are loaded
  • create a bunch of NavMeshLinks between NavMesh to allow path finding across chunks
  • only compute NavMesh for active creatures types (never have the 12 creature types active on all chunks)
    It works quite fine, but with some problems when finding path through chunk borders + some limits about the number of active NavMeshLinks

That’s why when I saw so much peoples were happy with A* Pathfinding Project, I decided to try it :wink:
I had to buy the pro version to have access to RecastGraph

But after several hours of analysis and forum search, I’m not sure that I can achieve what I expect with A* Pathfinding project.
From my understanding :

  • I need to create a RecastGraph for each creature type (as the NavMesh parameters and layer mask are setup at this level)
  • I need to setup RecastGraph with “Use Tiles”, and align the “Tile Size” with my chunk size
  • I need to setup the size of the Recast Graph to cover the whole world
    First difficulty here : I’m limited to approximatly 40km x 40km (otherwise I receive a message “Too many tiles maximum is 524288”)
    Not a clear blocking point, but it put a limit where there was none until now.
  • I need to deactivate “Scan on awake” to avoid waiting a long time at startup
  • I created a simple script to set “scanEmptyGraph = true”, and start a global scan (otherwise UpdateGraphs is not working)
    This allocate 400 000 empty tiles. looking at GC memory, I observed 80 Mb of empty data, for each graph / each creature type ;-(
  • I try to update the graph around existing creatures.
    For this I found “AstarPath.active.UpdateGraphs(bounds)”. It works, but it computes All graphs => for all creature types.
    I didn’t found a way to update only the graph I need
  • I try to free memory on deallocated chunks. The only way I found is to call “ReplaceTile” with empty array. Seems to work, but pearhaps there is a better way ?

So I’m confused now :

  • The framework seems stable and performant
  • I’m impressed with the connexion between tiles : so far it looks much better that my standard unity navmesh implementation
  • But I’m stucked with a huge memory usage, world size limits, and much higher computation time (for all graphs, instead of 1 or 2 graphs depending on spawned creatures types)

So my questions are :

  • Is there a better way to achieve our needs ?
  • Is there a way to avoid consuming so much useless memory ? (for example replacing NavMeshTile[] with a Dictionary<TileCoords, NavMeshTile> as I do with my unity standard navmesh implementation)
  • Is there a way to update only a single graph in a specific area ?

Thanks a lot for your help
Goreduc

Hi

How many players do you need? If there are few enough players, you may instead want to use one or more small moving graphs. See ProceduralGraphMover - A* Pathfinding Project

That said, your requirements are not the easiest to satisfy.

Ideally, you shouldn’t simulate your game that far away from the origin. Floating point precision issues with the position of objects start to become really noticeable at those large coordinates.

Hi

Thanks for your quick answer !

Yes I know well that these requirements are no easy to achieve :wink:

About ProceduralGraphMove, I saw in the documentation a warning about “When the graph is moved you may notice an fps drop”. And I think you are talking about a single graph.
In my case, I would have to make 1 graph per player (up to 10) * 1 per creature type (12 for now) > up to 120 graphs on server side to recompute when players move, and a lot of useless computation (recompute multiple times the same area for nearby players, compute graphs for creatures type not able to spawn in this part of the world…)
Nethertheless, I will add a test on this in the next sprint

Thanks again !