Parenting an object causes Collider2D to stop working

Hey there, I have a question about parenting and colliders.

I have player, box and wall game objects. Both player and box have their own box collider 2D and rigidbody, both dynamic (at first) and both work just fine and are confined within the walls no problem.

However, I implemented a grabbing function in which the player grabs the box while a key is pressed. I’m using this code to do that:

if (m_IsHoldingGrab)
       grabbed.transform.position = transform.position;
       grabbed.transform.parent = transform;
       grabbed.GetComponent<Rigidbody2D>().isKinematic = true;

       grabbed.transform.parent = null;
       grabbed.GetComponent<Rigidbody2D>().isKinematic = false;

Grabbing works just fine, but suddenly my box can’t collide with anything while it’s parented to the player. Is there a way to make it still collide even thought it’s parented?

P.S.: Here’s the Rigidbody2D definitions for my box and player:




Thanks for the replies! I fixed it by not changing the rigidbody’s body type at all and changing the gravity scale instead. Works like a charm now.