I have a scene with more than 25000 trees. The problem here is that the capsule colliders on the trees are extremely heavy on the CPU.
the physics.simulate gets overloaded according to the profiler.
Is there anything i can do to optimize my scene?
Like de-activating colliders when they reach a certain distance from the player?
25000 trees is much in excess of what you should (and realistically need to) display at a time. You need to implement a culling system that culls trees when they reach a certain distance, both physically and graphically, as you correctly guessed. The systems should be similar but not have identical behavior physically and graphically. A tree which is graphically culled could still respond physically, and vice versa.
When implementing your culling system, you should afford some attention to your choice of datastructure. Do not just store references to all 25000 trees in one long List< Tree >, for example. Traversing this list every frame to update the sub-collection which is currently in range to figure out which colliders and renderers to enable and disable will quickly turn out to be very expensive.
Consider instead a cell-based or tree-based (no pun intended) datastructure for your trees, which splits the references up into groups that are geographically close to each other. Then, every frame, first figure out which cell(s) you’re in, or close to, then perform the checks only against trees belonging to those.
My hardware has no trouble rendering all the trees. The only thing slowing it down right now is the physics. Turning the colliders off makes the game run just fine. Also due to occlusion culling and Lod. There is never more than 50-100 trees drawn.
I guessed as much, when you mentioned occlusion culling and LOD. But those mechanisms are rendering optimizations. They cannot help you optimize the physics part. The provided instructions should help with that.
My hardware has no trouble rendering all the trees. The only thing slowing it down right now is the physics. Turning the colliders off makes the game run just fine. Also due to occlusion culling and Lod. There is never more than 50-100 trees drawn.
– J-FDo you have any idea where i could start off?
– J-FI do own a pro license.
– J-FI guessed as much, when you mentioned occlusion culling and LOD. But those mechanisms are rendering optimizations. They cannot help you optimize the physics part. The provided instructions should help with that.
– CHPedersenI sure know that. I already have taken full advantage of both LOD and occlusion culling.
– J-F