Support Forum

Pet following through large chunked 3D world

Hello,

(Very) large 3D open world. Split in chunks that are loaded/unloaded at runtime as the player explores.

The player can have a pet. The pet should follow them throughout the entire world, wherever they go.

I use Recast Graph, and I would prefer to cache it rather than generating it at runtime.

How should I proceed?

  1. Have a graph for each chunk, and then somehow “join”/“delete” it from the existing graph as the chunks are loaded/unloaded? (Is that possible)
  2. Re-generate the recast graph at runtime each time a chunk is loaded/unloaded? I do have performance concerns.
  3. Each chunk has its own A* component and graph cached, and then somehow the pet’s “ownership” is transferred from one chunk’s A* to the other’s when the pet is near the border? (Not sure if possible or how to go about it)

Alright, I’m seeing the Procedual Example Scene, which is pretty good, but from what I’m understanding:

  1. It is recalculating the graph at runtime when I’d rather have my chunks cached.
  2. I don’t necessarily want to move a graph. I just want to mutate “the graph” as chunks are loaded/unloaded, because it’s not just pets that I will have using the pathfinding system, but also other stuff that comes with the chunks e.g. patrolling monsters that might actually go from one chunk to another, granted that they are both loaded.

So I’d still rather be able to load/unload cached graph “chunks” and then add/remove to an existing graph.

Hm. I don’t think it’s actually possible to append cached graph chunks. Does that mean that I will need to re-compute the recast at runtime every time a chunk is loaded/unloaded?

Hi

In the beta version, there is a (very) new component called NavmeshPrefab that might be suitable for you. Take a look at NavmeshPrefab - A* Pathfinding Project

This is very new functionality, so there may be some rough edges.

Wow, reading the page that sounds pretty much exactly what I need. I will experiment with it - thank you!

It should work even with multiple recast graphs right? e.g. I have one for monsters and another for giant monsters, so a single NavmeshPrefab should be able to provide for both? Or do I need two NavmeshPrefab instances per chunk?

Also, I don’t suppose there’s the same functionality but for the other graph types, such as grid? Not that it matters in my use case since Recast is pretty good, but just curious.

1 Like

You’ll need two NavmeshPrefab instances. You may also have to apply/scan them manually from code, since otherwise they will associate themselves with the default graph (first recast graph in the scene). But experiment with a single monster type first :slight_smile:

No. There’s also less need because grid graphs tend to be much smaller and also much faster to scan (especially in the beta).