Destroy rigidbody2D after collision?

Hi, in my 2D game, I have bombs that try to drop on the player. However, I’ve hit a bit of a problem. When the bombs explode, if the player has the shield activated, I want them to be able to pass through the explosion. (I have a 2D animation for the explosion). For this, I believe I need to remove the 2D collider and 2D rigidbody. Here’s where the problem is. Here is a bit of the code with the part regarding the collisions and explosion:

IEnumerator explosion()
	{
		yield return new WaitForSeconds(1);
		Destroy(this.gameObject);
	}

	void OnCollisionEnter2D(Collision2D collision)
	{
		if(collision.gameObject.name == "cube")
		{
			animator.SetInteger("Bomb_State", 1);
			bombexploded = true;
			rigidbody2D.isKinematic = true;
			Destroy(this.gameObject.collider2D);
			Destroy(this.gameObject.rigidbody2D);
			StartCoroutine(explosion());
		}

		if(collision.gameObject.name == "metaball")
		{
			animator.SetInteger("Bomb_State", 1);
			bombexploded = true;
			rigidbody2D.isKinematic = true;
			Destroy(this.gameObject.collider2D);
			Destroy(this.gameObject.rigidbody2D);
			StartCoroutine(explosion());
		}
	}

When I try this code, however, Unity crashes. It does not crash if I remove the “Destroy(this.gameObject.rigidbody2D);” but this then does not do what I want it to do. My guess is that the problem lies in trying to destroy the 2D rigidbody in OnCollisionEnter2D, as OnCollisionEnter2D depends on the 2D rigidbody. But surely there must be some way around it? Thanks.

hi:
1- use tags not names like this : if(collision.gameObject.tag == “cube”) note you have to tag your objects in unity and tag it the same as in the script for example your tag in unity must be cube .

2- you don’t need destroy (this.gameobject) and Destroy(this.gameObject.collider2D) and
Destroy(this.gameObject.rigidbody2D) just use destroy(gameobject) and to destroy other
gameobject use destroy(collision.gameobjects).