Support Forum

Recast graph size, updates and expansion

So i have a procedural scenario, we have connected “rooms”.
Due to the nature of how it is architected, there is a scenario where rooms are inserted /moved randomly on runtime.
I don’t understand how to properly integrate it with recast graph.
I can precalculate the bounds of the graph based on the initial room choice, but this means that the total bounds can be later expanded by randomly inserted ones, how does the recast graph handle it?
Does it recalculate the whole graph, or it only adds missing internal data?

I also tried to set recast graph to high size of over 1000 units, this however leads to insane initialization cost and memory footprint. I was reading on the github implementation of the recast, and it says something along the lines of “voxelizes meshes”, as i understand it is supposed to only voxelize participating meshes, but it seems it is preallocating internal arrays, i guess there is no way around it?
Is the data value based? Is there any optimization i could do? Is there some “flyweight pattern” where only voxels that are needed are allocated?

Event in case of a smaller graph that only encompasses existing room bounds, it would reallocate if the bounds were changed?
Main question is - what should i do, what is the best approach that would allow arbitrary growth of the bounds without massive performance hit?

Hi

Sorry for the late reply, I’ve been sick these last few weeks.

What you could do is to use the scanEmptyGraph option on the recast graph.
Disable A* Inspector → Settings → Scan On Awake and then when starting your game do:

AstarPath.active.data.recastGraph.scanEmptyGraph = true;
AstarPath.active.Scan();

This will fill the recast graph with completely empty tiles. After this, you can use graph updates to recalculate only the tiles you want. When a recast graph is updated, only the tiles touches by the given bounding box are recalculated. You would still need to have a fixed size of the recast graph when starting out, but if you have reasonably big tiles (maybe tile size 128 or 256) then you can have quite a big graph filled with just empty tiles to start with.

This looks exactly like what i need, thank you.

1 Like

Yes 4k*4k graph near instant init. Thank you big time, alleviates all issues.

1 Like