I have many varied building pieces that get put down by the player over large areas.
So far I’ve been using scan by mesh, and just doing a bounds update around the piece being placed which may be overlapping with several other mesh already placed, manually calling GraphUpdate(bounds).
I’m wondering about performance or the recommended pattern to use after reading the docs for RecastNavmeshModifier. It talks about if I scan by mesh, then it will scan all mesh in the entire scene even if I only update a small area? Is that right?
I could put RecastNavmeshModifier on each build piece and only update the ones that overlap the bounds of my update? eg. using RecastNavmeshModifier.AllInBounds()
I can’t see this being a huge issue really. Are you calling this very often or anything, or running into performance issues so far? In my head this seems like the right way to go
I call it every time a build piece is placed by the player or a worker completes building something. It shouldn’t be happening more than a few times a second at most. My concern was the comment saying it scans every mesh in the scene. I’d like some clarification on what that actually means.
From my testing and operation that seems to be correct. I tried to only update within the bounds of one RecastNavmeshModifier and it would always scan ones outside of it as well.
When a recast graph is updated, this is always done on a tile-by-tile basis. So calling UpdateGraphs(bounds) will update all tiles that the bounding box touches (+a small amount of margin). If you issue multiple graph updates in the same frame, the recast graph will internally try to collapse overlapping updates into a single update.
If you use ‘rasterize meshes’ in the recast graph settings, it will, however, have to iterate through all meshes in the scene, to determine which ones are inside the bounds of the tiles it is updating. Depending on your scene complexity, this may be expensive.
If you use ‘rasterize colliders’ it can instead use the physics engine to find all colliders overlapping with the tiles, which is much faster.
But first, check if this actually makes a difference in the profiler.