Navmesh cuts for 1000's of objects

  • A* version: 5.3.7
  • Unity version: 6

I have a terrain with a large number of trees on it. To speed up the server I manually instance these so only the x closest to the players are actually game objects. The trees can be cut down and also respawn. I want to add navmesh cuts to trees so that they are impassible when standing and not when cut down. However, the whole point of my instancing logic is to limit the number of game objects in existence at any one time. It appears that each navmesh cut requires a game object to exist. Is there another way to achieve what I want without having to have 1000’s game objects just for the cuts? Almost like just an area cut I can specify and then activate and de-activate. The areas are fixed in place, they will never move, and I have an instance object for each tree I can associate the area with (and any other data I need). Thanks for taking the time to read!

As is normal, the act of writing down focuses the mind. I think I can do this by having dummy colliders where all trees are just before the scan. Then remove them after the scan is complete. They when I tree is cut mark that area as walkable and vice-versa when the tree respawns. Does that sound reasonable to people with far more experience than me!?

Relatable. :skull::skull:

I think this falls in the “hey if it works it works” category. You can also have multiple NavmeshCut on the same game object. Managing those may get a little tricky but I believe that would also work.

I might try the multiple navmeshCuts approach. My ideal generally works, but if I have the colliders when I scan I get holes which are never walkable. So I just mark walkable, not walkable now. But I don’t know in practice whether the nodes it marks will be too big and I am not at the testing stage yet so having another possible alternative make me feel happier!

Also. If you use unity’s built-in terrain system, the recast graph supports grabbing the colliders from any tree prefabs you use via that system.

For the maximum flexibility (but some additional code) you can also feed custom meshes into the recast graph.
See CollectionSettings - A* Pathfinding Project
but I wouldn’t recommend this for most use cases.

I don’t know why I didn’t think of this, but you can also set all tree objects as an obstacle and then manually modify the graph during runtime to set the area as walkable when needed.