Why is there a Physics2D.Simulate spike with several edge (~20) colliders?

So I have a scene with several rotating rings. The basic idea is that the player jumps between rings without hitting the particle systems. To control the player I have a circle collider that the player raycasts against to move forward and backward. This circle collider is where the grey circle is in the image I attached, its just not highlighted. To detect if the player hits a particle system, I have an edge collider that is on top of the particle system as shown by the green line in the picture.

I have a relatively large spike in Physics2D.Simulate when I run the game with the edge colliders. I’m usually at ~1-2 ms without the edge colliders and upwards of 10 ms with them. I re-scale the parent object so that the rings increase in size over time and make room for new rings to appear in the center. The parent object that is re-scaled contains only the particle systems and edge collider. I’ve already disabled collisions in the matrix, so only the edge collider and the player interact.

Could the spike be caused by re-scaling the parent object every frame? Would it be better to just set edge.points each frame? I thought about using a set of box colliders to create a collider on top of the particle system in an arc shape, but I would need several boxes per particle system and would end up with 5 to 10 times as many colliders. Is there a better way to do this?

Do the particle systems have rigidbodies attached? If so make sure you change their transform via rigidbody.transform instead of directly accessing transform on the gameobject. I had similar spikes in my game and they reduced a lot by making this change. If you access and change the transform directly then the colliders have to be recreated. Instead, change it via rigidbody.transform. Hope this is helps!

Hi there

I believe (could be wrong) edge colliders are like mesh colliders in 3D, and thus contain an optimised representation internally for doing queries against (such as collision tests). However, this optimised representation is based off the object at a certain scale, and thus needs rebuilding if you rescale (which is slow).

If you remove the scaling every frame I suspect it’ll speed up no end.

Given what you’re doing is pretty simple (the edges are just portions of a circular edge, so easy to work out when the circular player has hit them), I’d recommend just writing the ‘have I hit the edge’ maths yourself rather than rely on the physics engine to do it.