Improving 2D collision detection performance with PolygonColliders

I’m working on a first prototype for my game. The game will have a large amount of sprites, so generating colliders by hand is something I’d like to avoid. So I’m letting Unity generate the colliders for me. I’m using PolygonColliders because sprites can be highly irregular, so they add a lot of realism to collisions.

In my testing, the framerate drops to ~30 (from 60, because VSync) when around 50 sprites are on screen. I don’t expect to have this many enemies on screen, but I’d like to make mobile builds if I can get the performance high enough. So: PC builds might be fine at this point, mobile probably not.

Some more info about the setup:

This is my test scene with ~50 enemies (Yep, those are maplestory sprites, used as placeholders):

This is the setup of one of the large guys:

As you can see. it generates a collider with 76 points. It matches the shape quite nicely, but obviously adds a lot of overhead. I’m also switching between colliders based on the current frame, but as far as I can tell from the profiler, that’s not the issue. I’ve also made sure they’re not triggers, since that also adds a lot of overhead (Framerate < 15 with just 10 enemies).

What else can I do to improve performance? is there any way to have Unity generate PolygonColliders with lower detail? Any cheap to run algorithms I could use myself to generate colliders? Is there a way to disable collisions between all monsters? Maybe that’s what’s tanking my framerate.

And a screenshot of the profiler:

I’ve managed to find how layers interact with physics, added a layer for enemies and told it not to interact with itself. This brings the framerate to ~60 with 50 enemies. A nice gain, but not enough for mobile I suspect.

Make sure the layer also does not interact with any other layers that it isn’t actively meant to collide with.

Also if you switch to multiple box/circle colliders it probably will be faster - polygons require more complex math to detect a collision, no to mention that every triangle in the polygon can be involved in the test, which is a lot of work.

That would definitely be better for performance. Unfortunately, the overhead of creating the colliders for each and every enemy would be too much for me to handle.

reducing paths & points from polygoncollider helps alot also.

tool for removing extra paths & points : Unity Asset Store - The Best Assets for Game Making