Why is my debris causing serious lag?

So I have a prefab explosion and it contains about 12-15 large pieces of debris. Each piece has a capsule collider and rigidbody attached. Explosion works as expected, but then as the debris field falls to earth the game just lags. We’re talking about 5-10 seconds per frame.

If we can’t figure out what’s causing this (and I’ve already tried reducing the debris count), maybe someone can give me a suggestion for handling debris? While I would like enemy debris to be able to hit the player’s helicopter, I’d much rather not have lag.

(Incidentally, there are a lot of meshes on screen at this time, as it’s drawing the city, plus two or more helicopters, plus debris. Maybe the volume of meshes is too great?)

Just to be clear on terminology here,

Does your game produces lag - a delay between input and effect (due to poor network connection or other external factors), or “performance drop” where the actual frames-per-second count goes down? I’ve seen too many people refer to performance drops simply as “lag” even though this is technically incorrect.

If you game produces performance drops when the debris contact anything, then I’d suggest checking several things:

  1. When the performance drops, do you have any exceptions raised in the console? Any null-references or such?
  2. Since debris you are spawning is a prefab (I assume it is, since it already has collider and RB), do you perhaps have any scripts attached to it’s OnCollisionEnter functions that could cause some poorly optimized code to run?

If your game produces actual lag, then I’m out of ideas.

Learn to use the profiler and you can discover what is affecting your game’s performance at any time. Without it, we’ll all just be guessing…

So, I’ve received no response as to why 5-10 pieces of debris would cause the Physics Engine to freeze up the game. The Profiler shows between 1,000 and 2,500 collisions being processed in a single frame, which would certainly account for why that would happen, but that makes no sense to me.

For now, as a workaround, I’m moving the debris manually, not using Physics, and it looks great but there are no collisions, which would be nice if debris could hit the player or the ground. Still, manually moving each piece of debris (and now we’re up to like 65 pieces), frame by frame, isn’t even putting a dent in the processing time or frame rate. So it looks great and works great, but with no collisions.

If anyone can figure out why 5-10 pieces of debris would freeze the system with thousands of collisions, I’d still like to know.