Ok I think I’m going to need to illustrate my full gameplay scenario and ask for advice. I have tried to be a big boy and solve it myself, but I think it’s time to ask for help haha.
I have a world that looks like this.
It is broken down into chunks, each with their own mesh.
I need:
- Standard collisions so I can walk on stuff with a character controller.
- To disable collisions on some of these tiles/boxes. They will be destructable, so shooting them can destroy them. They will regenerate though so it’s a temporary disable situation.
- To generate the terrain quickly.
- To have performant terrain.
- To raycast against the terrain. But doing my own implementation against the terrain is acceptable, so I don’t ‘need’ colliders on everything all the time.
My approach so far, ignore the rendering side of things:
-
Create a pool of box colliders per thread.
-
Loop through geometry and cover as many boxes with as few colliders as possible (see fig. 1). I am ASSUMING it’s wise to not use 1 collider per gameplay box/tile.
-
Set the colliders’ geometry by updating boxGeometry via unsafe context
-
call CompoundCollider.Create. Then reusing the same pooled colliders for the next compound.
-
Put a big trigger around the whole chunk. When nothing is in the trigger, I remove the PhysicsCollider from the entity (stored in a component) and put it back on when something enters the trigger.
Doing this made me feel smart because I assume it’s a good optimisation. But probably it’s stupid. Is it?
fig.1. Example of collider generation to cover multiple boxes with one collider. Each colour represents one collider.

Pros:
- It’s fast, I have avoided the expense of BoxCollider.Create
- I am minimising box collider counts by covering multiple boxes per collider (I assume good).
- Entire chunks/compounds are removed from the simulation when their bounding trigger is empty. (is this a pro? I don’t know…)
Cons:
- I cannot disable individual game play boxes in the compound collider, because there is no 1 to 1 relationship between game box/tile and collider. I do not want to rebuild the compound, it’s too slow.
I am now considering how to proceed.
Thought 1:
What if I try 1 collider per box. This would produce millions of static colliders. Is this madness, or is dots physics Sparta? I’m betting on madness.
This would allow me to disable individual colliders by changing their CollisionResponse.
I just doubt that many colliders is the way to go.
Thought 2:
A completely custom physics solution for this terrain, plus future voxel terrain?
I hope I don’t need to do custom… but is it the way to go here…?
Thought 3:
Each frame, remove all terrain colliders, and place them on tiles next to dynamic entities like players, or in front of things like projectiles.
This is basically a half backed custom solution anyway lol. What a hack lol but if it works…
Thought 4:
@steveeHavok once mentioned using a ‘custom physics shape’ like the ‘terrain collider’, but it might be a rabbit hole… Is that something that could solve my woes potentially? I have no idea what is possible in this realm lol.
Thought 5:
Split the rendering chunk into smaller pieces for physics chunks, so that rebuilding compound colliders is not as long, perhaps 8x8 or 16x16 or something. It would be more colliders overall as I couldn’t optimise larger pieces of terrain, and I would have to introduce child entities for it, and it would still be more computation to rebuild compounds than just disabling something somewhere, but could work ok.
Questions:
- Is 1 static collider per box going to destroy Build/StepPhysicsWorld performance? I will try it soon haha.
- Is the cost of removing and adding many colliders per frame bad for unity physics, or perhaps the statefulness of havok physics?
- By setting the CollisionReponse to none on a collider, does that take it out of the physics collisions calculations, or does it still go through at least the braodphase?
- Can a custom physics shape help??
- What would you do if you were me…?
Appreciate the time taken to read this ^^.
Cheers.
edit: lol yes, millions of colliders is a bad idea. frame rate dies to CheckColliderIntegrity job.