Could GameObject have multiple bodies?

Hello all,

I was going through the Unity3D docs and some google search but can not find the answer and understand the mechanics of adding multiple components to GameObject. The whole concept is simple - just use AddComponent<$ComponentType$>() as much as you like and fill your GameObject with features and traits, however there seem (in my view) to be some ‘special’ cases like this one f.e.:

Could I add more then one Rigidbody2D to single GameObject?

If I can then what of multiple Rigidbodies will return Collider2D.attachedRigidbody when I’ll add some?
If not then where I could find the info about special cases like that one? Are there any?

Also what will happen if I add Collider2D to GameObject with no body ( Collider2D.attachedRigidbody will be null or same as parent body) and then attach Rigidbody2D? Would the Collider2D.attachedRigidbody change?

Objects can have 1 Rigidbody at-most, but an object can have multiple colliders.

If your goal is to have multiple Rigidbody components governing a “single” object (one limb heavier than another), then you could just attach one to each limb.

You can also check your question pretty easily:

public class ColliderRigidbodyCheck : MonoBehaviour
    void Start()
        var col = this.GetComponent<Collider>();   
        Debug.LogFormat("[1] Attached rigidbody is null? {0}", col.attachedRigidbody == null);

        var rb = this.gameObject.AddComponent<Rigidbody>();
        Debug.LogFormat("[2] Attached rigidbody is null? {0}", col.attachedRigidbody == null);

        DestroyImmediate (this.GetComponent<Rigidbody>());
        Debug.LogFormat("[3] Attached rigidbody is null? {0}", col.attachedRigidbody == null);

Which shows that the attachedRigidbody does reflect changes with each call: