Couple of random questions - Colliders, Collision Meshes etc.

Hello,

I’m curious about a number of aspects related to physics that not able to find definitive answers for…

  1. I have a lot of trees in my game. All of them will have a single, vertical capsule collider for the trunk collision. Is there any way to supply these to physics without having an equal number of GameObjects? Should I just add them all to a single GameObject with different centers specified? Would it be better to spread these over a number of GameObjects for spatial partitioning reasons - i.e. so PhysX doesn’t treat them all as one huge object across the entire world?

  2. I have a large polygon landscape (not Unity Terrain - just a polygon soup). It’s static, but procedurally generated at runtime and assigned to the mesh (so I don’t think the “static” tickbox does anything in this situation). But anyway, is it better to just give this entire landscape to Physics as one huge mesh? Will it do it’s own spatial partioning/optimisations on it?.. or should I split it up into blocks?

Basically, it’s not clear to me what PhysX does and does not do internally when you supply it meshes. In both of the above cases they do not move - therefore are there any hints I can give PhysX in that regard to improve performance?

Thanks in advance!

Y̶o̶u̶ ̶c̶a̶n̶’̶t̶ ̶a̶s̶s̶i̶g̶n̶ ̶m̶u̶l̶t̶i̶p̶l̶e̶ ̶c̶o̶l̶l̶i̶d̶e̶r̶s̶ ̶o̶f̶ ̶t̶h̶e̶ ̶s̶a̶m̶e̶ ̶t̶y̶p̶e̶ ̶t̶o̶ ̶o̶n̶e̶ ̶g̶a̶m̶e̶ ̶o̶b̶j̶e̶c̶t̶.̶ ̶Y̶o̶u̶ ̶c̶a̶n̶ ̶h̶a̶v̶e̶ ̶a̶ ̶b̶u̶n̶c̶h̶ ̶o̶f̶ ̶p̶a̶r̶e̶n̶t̶e̶d̶ ̶g̶a̶m̶e̶ ̶o̶b̶j̶e̶c̶t̶s̶ ̶e̶a̶c̶h̶ ̶w̶i̶t̶h̶ ̶a̶ ̶c̶a̶p̶s̶u̶l̶e̶ ̶c̶o̶l̶l̶i̶d̶e̶r̶,̶ ̶w̶h̶i̶c̶h̶ ̶i̶s̶ ̶r̶e̶f̶e̶r̶r̶e̶d̶ ̶t̶o̶ ̶a̶s̶ ̶a̶ ̶c̶o̶m̶p̶o̶u̶n̶d̶ ̶c̶o̶l̶l̶i̶d̶e̶r̶.̶

Probably only Unity staff can definitively answer these questions and hopefully they will, but in the unfortunate event that they don’t - there is a physics debugger https://docs.unity3d.com/Manual/PhysicsDebugVisualization.html, so you can kinda deduce some things based on what information it provides.

Also when you say a lot of trees, or a large landscape, it may seem large to you, but the engine may be totally ok with it, so before you worry about what size and amount of colliders is too much, take a look at the profiler https://docs.unity3d.com/Manual/Profiler.html and if it doesn’t show physics being an issue, just enjoy your trees and landscapes.

Pure speculation: if you have a bunch of separate game objects with colliders, some form of spatial optimization will take place. If you have them all as one compound collider, this may or may not affect the engines’ ability to spatially optimize them. As for having a huge terrain mesh collider - very likely Unity doesn’t do any optimizations there, since it is much easier for the developer to split geometry into smaller elements than it is for Unity engineers to come up with a smart mesh partitioning solution.

You could try having a high-resolution terrain mesh, but supplying a simplified (decimated in blender terms) copy as a mesh collider if you notice performance issues.

Since when? Maybe I’m not understanding what you’re saying, but I do it all the time for my compound colliders and never had a problem.

Indeed. I stand corrected, guess it changed at some point and I missed it.

Thanks for the feedback. In my case, given these are all just upright capsule colliders that just represent a bunch of static tree trunks that don’t really do much, I am keen on avoiding having hundreds of gameobjects that don’t really do anything. I am targeting mobile by the way.

I will experiment with splitting my terrain mesh up. It is made up over a number of different surface types, so I was thinking each type would be one mesh collider as to avoid seams/edges that can cause some issues - for example a ball rolling over a seam and bouncing up, when it shouldn’t if the surface is visually flat.

Splitting them up should also allow you to implement Occlusion Culling and/or disabling out-of-view portions of the terrain - either of which should increase performance.

Apologies if my reply came off rude. That totally wasn’t my intention and upon re-reading it did kinda sound snippy.