Why will OnCollisionEnter2D get called but OnCollisionExit2D/Stay2D will not

Hi everyone.

Firstly I’m pretty new to Unity and I’ve searched for an answer but nothing i’ve found has seemed to work.

I’m just trying to get my script to know when the player touches and leaves the ground. When my player hits the ground OnCollisionEnter2D is called but when the player jumps, OnCollisionExit2D is never called. In addition, OnCollisionStay2D is never called either. The ground has a 2D collider and my player has a 2d collider with a rigidbody2D attached. The rigidbody is set to neversleep with continuous collision detection.

Any suggestions would be really appreciated.

void OnCollisionEnter2D(Collision2D collision){
		
		if(collision.gameObject.tag== "Block" || collision.gameObject.tag== "CurrentBlock"){
				
			grounded = true; 
			doubleJump = true;
			print ("enter collision");
		}	
	}
	void OnCollisionStay2D(Collision2D collision){
		if(collision.gameObject.tag== "Block" || collision.gameObject.tag== "CurrentBlock"){
			print ("stay collision");
		}
	}

	void OnCollisionExit2D(Collision2D collision){
			
		if(collision.gameObject.tag== "Block" || collision.gameObject.tag== "CurrentBlock" || collision.gameObject.tag=="Player"){
				
			grounded = false;    

		}	
		print ("exit collision");
	}

I used a polygon collider with a concave polygon .And Unity Engine splitted them to some convex polygons.When the object move through the convex polygons ,it didn’t recieve OnCollisionExit2D from the prevouse convex polygon.

I tried posting this already and it doesn’t seem like it worked.

I’ve added a rigidbody2D to my ground and now I get exit and stay calls. I’ve also checked kinematic so that it won’t be affected by forces. I should’ve tried this to begin with and is a usable workaround. I’m gonna mark this as answered but I still think I should be able to get exit and stay calls without the rigidbody2D on the ground. I should only need one on the player as far as I can tell with the documentation.

Hi, you may try the code i attached, this code basically check if a transform is overlaping with an object of a layer.
To make this work you will need to add in the hierarchy inside your player an empty transform, then drag and drop this transform from the hierarchy view to the attribute Tranform of the script in the Inpector view,then in the layer attribute you can choose by clicking it (it will appear a combo box) the layer you want to add to the layer mask (all, UI, Character, and the ones you have created or none), the Physics2D.OverlapCircle checks if a transform overlaps with a circle of a certain radius in any of the layers in the LayerMask.
Hope it will help.

[36443-overlapcircle+example.txt|36443]