Recalculate PolygonCollider2d via script

Hi Everyone

Is there any way to recalculate the polygon collider via script to match my sprite ? When I change my sprite via the inspector I use OnValidate to update the spriteRenderer.sprite property.

void OnValidate()
    {
        renderer = GetComponent<SpriteRenderer>();
        renderer.sprite = idleImage;
    }

I would like this to update the polygon collider in the editor to match. In the same way clicking the cog in the corner of the polygonCollider script in the inspector and selecting reset does. I don’t want to do this at runtime so I dont think performance should be an issue, Any ideas ?

Thanks :slight_smile:

Hi !
Have you tried using this with Auto Tiling enabled? I’m unable to try this at the moment but it seems like it could do the trick for you?

Hope this helps!

Hi

No that doesn’t seem to work :frowning: