# Destroy object on Collision

I have a strange problem... I need a 2D projectile to destroy itself after colliding with an object. I have used all of the different ways to do this on the internet but to no avail; the object always collides with the way but is never destroyed! This is my code:

public void OnCollisionEnter(Collision2D other)
{
Destroy(gameObject);
}


The projectile is a prefab I made and it's attached to a controller I made for the main character. The console is giving me the error, "This message parameter has to be of type: " ... and I'm not sure what type is " ".

The projectile has a rigidBody2D attached to it and a circle collider. The wall is an empty object with an edge collider. I know that there is a collision because the projectile hits the wall and rolls down it. However, my function "public void OnCollisionEnter(Collision2D other)" is never activated, and I don't know why. I'm not sure what you mean by framework... I'm totally new to unity and programming.

When the object hits the wall it simply rolls down it and lands on the ground.

• You should edit your question and describe what is the framework you're using. We need more details. – Alexandre Vaillancourt Feb 4 '16 at 4:09
• I agree with @AlexandreVaillancourt. It's hard to help with so few details. And by the way, you mean that no collision is being detected or that it is being detected but the resolution (i.e. destroying the object) is the part that is not working? – MAnd Feb 4 '16 at 4:12
• Unity is your framework. This site is not Unity answers, it's a general question and answer site for Game Development (where Unity related question are welcome). This means that you can't assume we know what you're talking about if you don't mention you work with Unity (or anything else). Since mind reading via the Internet is not possible, you must describe your issue thoroughly. – Alexandre Vaillancourt Feb 4 '16 at 4:27
• Generally @AlexandreVaillancourt is right about trying to avoid delete this; but from context (and now the recent edits) this is Unity. Unity's Destroy() method just marks the entity for destruction, with the actual deletion occurring in a batch later in the frame, so it already handles this case for us, and this pattern of Destroy() use is safe. – DMGregory Feb 4 '16 at 4:30