Collision2d error message saying "type: "

I have been trying to learn collisions for 2d but for some reason it is spitting out this message when I try to run.

Script error: OnCollisionEnter
This message parameter has to be of type:
The message will be ignored.

public static TreeCol Instance;

void awake(){
	TreeCol.Instance = this;
}

void onCollisionEnter2D (Collision2D col){
	if(col.transform.name == "Tree"){
		Debug.Log("Hit tree");

		//if(Input.GetKeyDown(KeyCode.W))
			//Destroy(col.gameObject);
	}
}

I have this attached to the player object and have a 2d boxcollider attached to the “tree” with a trigger, I commented out the destroy object while I tried to get unity to stop ignoring the code.

Hello,

the players collider should not be marked as Is Trigger when using OnCollisionEnter2D(), the Tree can or doesn`t have to be as trigger.
I belive the function should be with Capital C as well, as: OnCollisionEnter2D.

  • Is the “Hit Tree” message printed into Console?
  • Is the name of object tree really Tree? You can also you tags, since when you create new objects, they always have postfix (Clone), so your If statement:

if(col.transform.name == “Tree”)

would no longer work.

  • are both objects using 2D collider? (2D Box Collider for example)
  • does at least one of those objects have Rigidbody2D component attached?