Best way to set different levels of detail for colliders?

I have a large forest environment with trees, rocks and bushes, all of these will have collision detection or triggering with the player. However, AI entities will have the obstacle positions baked into their navmesh so they don’t need to have collision with those aspects of the environment when the obstacles are too far away for the player to interact with. In order to stay under the physX collider limit in very large maps I want to instantiate colliders for most objects only when they become close enough to see, similar to LOD groups. I imagine I would need to also instantiate rigidbodies with them to avoid creating static colliders and rebuilding the static graph. What other considerations should I take to keep performance high?

The cap on colliders for Unity is 65536. If you’ve got that many trees that need to be collided with, all in one scene… that’s a lot of trees (even assuming you’ve got a lot of other things with colliders). You may want to consider having fewer trees, or finding a way of combining them into groups so that they share a mesh collider.

I would not, however, suggest that you instantiate them at run-time, as this would be quite costly to performance, as well. If you do plan to use rigidbodies (which I would at least suggest making them kinematic, to avoid unnecessary or unwanted physics calculations), you should save references to the trees in some sort of a buffer collection (an array or a list or something that suits how you plan to enable them in the scene). This way you can quickly and easily enable/disable them as needed, without worrying about memory leaks due to the garbage collector.

Additionally, I’d suggest picking trees that might not necessarily need to be collided with (say, trees that are up on a ledge that the player can’t climb to, for example), and simply not give them colliders.