Why does CompositeCollider2D require a Rigidbody2D?

Is there a reason why CompositeCollider2D requires a Rigidbody2D component to be present? Would it be possible to remove this dependency?

Every collider requires a rigidbody because a colliders’ shapes are created via the body itself as it owns them. They cannot exist on their own. When you don’t specify a Rigidbody2D component in Unity, the collider shapes are still created against the static ground body you can’t see that is created behind the scenes.

The composite requires this explicitly because it must ensure that everything being composite is attached to the same body. If you want it static then just set the body to static body-type. This is identical to not adding a Rigidbody2D component at all. There’s no disadvantage or performance impact in doing so as this is already done as I mentioned above.

3 Likes

Thank you for the clarification! Very useful info.

1 Like