What is Physics2D.Simulate, and why is it chewing up more than 100ms of frame time? And why does this not happen when using 3D physics?

Important Edit At Bottom Of Post

If I try this with 3D colliders and physics it get ~5-10x the performance

I made a fairly simple test scenario where I had a bunch of ships all shooting at a central target. Each turret has it’s own circle collider that’s used to check it’s range from a specific target (and to identify if a target has entered it’s range). They also have a 2D line cast to make sure their target is within line of sight, and is also within a certain range.

The projectile is a small sprite with a small circle collider attached and a rigidbody.

I have 80 turrets shooting one projectile every 10 seconds (staggered) and 4 turrets shooting 10 projectiles per second. I noticed the performance tank the more turrets I added, even if none of them where actually firing.

alt text

alt text

What is this Physics2D.Simulate, and what can I do about it’s horrible performance in this situation?

Additionally, Unity is only using ~11% of the performance available on the threads it’s utilizing, yet the frame-rate is so low. Any comments on that?

Edit: I tried instantiating 120 projectiles per second from a single unit to see if it was the rigidbody movement, after over a thousand projectiles I was still at 90FPS. It does not seem to be that. It also does not seem to be the OnTriggerEnter or OnTriggerExit behavior either, since that is under Physics2D.ContactReporting.

Edit2: I created a part of the scene with 80 empty gameobjects and added a circle collider to each with IsTrigger selected. When the projectiles fly through the colliders the game goes from 700FPS to ~1-2FPS in waves. It will be fine for a few seocnds, then the Physics2d.Simulate spikes to a few hundred ms for a second or two, then it goes down for the next 3-4 second, then back up, then back down. I can’t make much sense of it.

Screenshot of slowdown: alt text

Screenshot of colliders: alt text

GIF of firing: alt text

Hey,
I found a potential solution. If you go into project settings-> physics you can change the collision matrix and turn all collisions off except for collisions between bullets and units. Unnecessary collision checking could be hogging cpu resources.