Remove NavmeshPrefab OnDestroy

Hi,

I’m using NavmeshPrefab for procedural dungeon generation but when we leave the dungeon and clear it, the navmesh data from NavmeshPrefab is still visible from the Recastgraph.

Is it possible to delete the data from the graph OnDestroy? I tried to store the tile size of the Recast graph before generating the dungeon, then when we destroy it I resize it down again. This works fine the first time, but the next time it seems to throw errors. Then sometimes it doesn’t clear properly either and some linger (after the first attempt).

Either way, it would be nice to be selective/explicit about it so I can remove some in runtime. For example, it would be good to remove the navmesh from our main area before the dungeon, generate for the dungeon, then when we leave the dungeon we remove it.

Something to consider, though, is that we only turn on objects in the dungeon when we actually get to their room. If we don’t get there, we never generate it into Recastgraph so need to be sure to only delete it if it exists in the graph already.

Basically, it would be great if we can have access to the opposite of Apply available in the NavmeshPrefab script and able to have control when we apply/unapply it.

Wanted to bump this up in case it is not solved yet.

I managed to fix this issue by resizing the nav graph’s tiles to the tile count it was before we entered a procedurally generated dungeon.

Sometimes this causes an error but it still works.

Hi

In the next version, I’ve added a field called NavmeshPrefab.removeTilesWhenDisabled. It will make the NavmeshPrefab automatically remove the tiles it covers, when the component is disabled or destroyed.