Caching multiple Recast Graphs

  • A* version: [5.3.4]
  • Unity version: [2022.3.55]

I have a large game scene divided into Sectors/Regions. I have a specific Recast Graph for each Sector (NPC’s do not need to traverse between them and stay in their assigned Sector).

I have created a Cache for each Recast Graph and I also assign the appropriate graph to each NPC via their Traversable Graph in their FollowerEntity.

At runtime though. ONLY the CachedRecastGraph assigned in the Settings/Load component of A* is used and thus no pathfinding for any other NPC’s in any other Sector.

Is there a way to ensure all CachedRecastGraphs are used? Or does this have to be left so scan each Recast Graph at runtime.

Thank you!


FilePath

You can use some code on Start/Awake to apply a cached file to each different graph individually:

Thank you for the reply. I might be missing something…but I see how to do so with Loading/Saving/Caching graph data to 1 Recast graph, but not how to have Each Individual Recast Graph load it’s respective CachedGraph data

(Sorry I though I replied to the wrong post)

So if you want to have like, different areas randomly spawn and have their graphs loaded, you’ll want to use something like this:

void AddGraphsFromFile(TextAsset graphFile){
    AstarPath.active.data.DeserializeGraphsAdditive(graphFile.bytes);
}

You can then make each graph a TextAsset and load it additively, rather than from the cache. Each graph file can also hold multiple graphs and add them all.

2 Likes

I’ll give it a shot thank you so much!