How to connect a "PickUp" to my Player's GameObject

The main Character in my game flies around and needs to pick up various gameObjects Tagged “PickUp” that are randomly placed in my scene.

When my Character collides with the PickUps I would like them to attach to an “AttachmentPoint” (which is a child of my Character and only has a Transform Component).

My understanding is that once I detect the collision all I should need to do is attach the transform as a child of the “AttachmentPoint” and it should ‘stick’ to the character at the proper position.

Here is the code I have
void OnCollisionEnter2D(Collision2D coll) {

if (coll.gameObject.tag == “PickUp”) {
coll.transform.parent = transform.GetChild(0);

When I Play the game, I can see in the hierarchy that my PickUp is attached as a child to the AttachmentPoint, but it doesn’t attach to the Character as it flies around.
However, even while I’m flying around it jumps slightly trying to change its position.

How come the PickUp isn’t attaching to my Character?

Do you have a rigidbody attached to the PickUp? You may need to disable it and any colliders after collision. You may also need to set the transform.position of the PickUp object to 0, 0, 0 after you parent it, since its position is in world space prior to the collision, but parenting it will make its position local to the parent transform.

Thanks, that makes sense. Unfortunately, you can’t disable a RigidBody2D so I destroyed it instead.
Here is what I came up with:
coll.transform.parent = transform.GetChild(0);
GameObject pickUp = GameObject.Find(“PickUp”);
Destroy(pickUp.GetComponent());
pickUp.transform.localPosition = newVector3(0, 0, 0);

It’s a bit taxing on the CPU but it is now attaching properly.

The problem now, is that I would like the PickUp to maintain its weight so that when my Character is flying around with the PickUp it pulls him down more. By destroying the Rigidbody2D I lose that option… is there a solution???

Oh I forgot about Rigidbody2D not having an enabled flag… sorry about that. You may not even need to remove it. If there are any forces being applied to the pickups in any scripts, just make sure that doesn’t happen after its been picked up. You may also want to set any colliders attached to the PickUp to isTrigger, unless you want them to continue colliding with the environment.

Here is an example :

public class ExamplePlayerClass : MonoBehaviour
    {
        public Transform PickupAnchor;

        public void OnCollisionEnter2D(Collision2D coll)
        {
            if (coll.gameObject.tag == "PickUp")
            {
                coll.gameObject.transform.SetParent(PickupAnchor);
                coll.gameObject.transform.position = Vector3.zero;
                coll.gameObject.GetComponent<Collider2D>().isTrigger = true;
            }
        }
    }