Physics2D.PolygonColliderDecomposition - More Info?

Hey folks,

I’m trying to optimize my game for android devices, and I’ve noticed that my game spends 34ms per frame decomposing colliders for physics interactions. Overall it counts for 26% of CPU time.

I was wondering if anybody could tell me more information about this process and perhaps how to optimize it, as it’s causing a major bottleneck on low-end devices.

Thanks a lot!

Sam

Unity 2D engine is a version of Box2D engine which can only handle 8 vertices per polygon , in Box2D this could be increased but its not very recommended, Box2D also does not allow concave polygons so what unity does to go over this limitations is to allow you to create any complex polygon shape and then to Decompose it on “legal” Box2D polygons each one is convex and with 8 points maximum.

if you see the polygon gizmo on unity scene view, there are lines inside the main polygon shape, those lines make a legal poly they have always 8 or less points and always convex shape.

if you see in the profiler that Physics2D.PolygonColliderDecomposition is working hard is cause you probably are creating polygon shapes at run time, so internally the stem need to decompose them.

hope this helps, i am researching more info on this myself cause i would like to access to the decomposed shapes but seems that the decomposer is not exposed to the user, its just something unity does internally but you can’t read or call it by yourself… :frowning: