Any standard way to draw a PolygonCollider2D at runtime?

Imagine you’re making a board game with lots of irregularly-shaped little regions you need to click on (think of Risk).

PolygonCollider2D provides a convenient way to define and hit-test those regions. Hooray!

But there appears to be no built-in way to draw these regions in order to, say, highlight the ones you can reach. Boo.

I know I could iterate over the paths in the PolygonCollider2D and make a mesh out of it myself, and then render that with a material of my choosing. But man, that smacks of effort. Anybody know of some code already lying around somewhere to do this? I guess there’s Triangulator, which gets us partway there, but it doesn’t support polygons with holes, so we’d have to call it for each path in the collider and then either fuse them together somehow, or just live with multiple meshes.

Is there a better solution that I’ve overlooked?

There’s very rarely a need to do something like this, so I’m sure theres no comfortable solution and you’ll probably have to settle for something that kinda works.

My approach would be to use a line renderer and copy the points out of the polygon collider. (you might even be able to copy the whole array of points instead of iterating through and copying each point)

Sorry, I should have specified that I want to draw a filled polygon, not an outline of it.

But anyway, you’re probably right — time to just roll up the sleeves and code something!