Moving many 2D triggers is slow. Why?

Hi, I’ve got a scene with about 1600 2D colliders set as triggers and a rigidbody that is disabled. The problem is: when I move all triggers at once, it takes too much time on the main thread.

To clarify, actually moving the responsible GameObjects (changing transforms) takes about 13 ms when profiled. But at the same time, the movement is noticeably sluggish and the basic Game View Stats report around 120 ms. So clearly there’s something going on behind the scenes. I strongly suspect Physics2D is the culprit here, because when I disable half of my triggers, the performance improves rapidly (to 40 - 50 ms).

Is there any way to bypass these extraneous physics computations? I really need only trigger detection.

All right, I didn’t manage to figure out the exact cause behind all this. But even if I did, most probably I couldn’t have done anything about it. It’s hardwired in Unity.

The bottom line is: don’t move so many primitive 2D shapes at once as a part of continuous interaction or even real-time updates. Unity cannot handle it smoothly. My experiments show that about 500 simple triggers are barely manageable on a modern PC, giving close to 30 FPS.

My solution was to disable as many colliders as possible before performing the movement. It might not work for everyone. You might want to distribute movement across several frames as @rutter proposed, or simulate rapid movement of many objects in your script data and then apply it less frequently. Other than that there aren’t many options but to write your own trigger management system, bypassing Physics2D.

This was experienced in Unity 4.5.2 and 4.5.4.