How to scale a GameObject without scaling the collider

How can i scale a GameObject without scaling the Collider. I am using a PolygonCollider2D and in my case I can not use multiple GameObjects to split the Rendering and the Physics.

Hi fraanns,

One possible solution would be to disable the collider prior to the scaling, then re-enabling it after the scaling.

I don’t have Unity open to test this out, but I think that may be an easy route to test.

Alternatively, you may be able to store the collider details pre-scaling (bounding box, etc.), then redefine the collider post-scaling.

Regards,
Ezro

I think for a PolygonCollider2D, you will have to rewrite the paths. As an alternate, you could have two copies of the game object, one with the path but the renderer turned off, and a child without a collider that you then scale.

I know i’m 11 years late but i found a nice solution to this, hope this will help someone in the future:

So, all i did is saving collider fields in world space

_colliderDefaultCenter = transform.TransformPoint(_collider.center);
_colliderDefaultSize = transform.TransformVector(_collider.size);

and then reapplying them in local space:

_collider.center = transform.InverseTransformPoint(_colliderDefaultCenter);
_collider.size = transform.InverseTransformVector(_colliderDefaultSize);