Physics2D.OverlapCircleNonAlloc not working.

Hello guys and thanks for reading through my question.

I’m having a problem with Physics2D.OverlapCircleNonAlloc and although it’s not a big trouble I’d still like to know what exactly I’m doing wrong. The following code is executed in the Update() Method.

        Collider2D[] GroundOverlap = null;
		if(Physics2D.OverlapCircleNonAlloc(GroundedCheck.transform.position, 100F, GroundOverlap, Ground) > 0)
		{
			IsGrounded = true;
			Debug.Log(GroundOverlap.Length);
		}

This if statement is never executed, no matter what I try. The LayerMask ‘Ground’ is set to Everything (for Debug purposes) and the GroundedCheck item is at the feet of the player. Now the Radius is set to 100 (also for Debug purposes) but this does not seem to yield anything. Also tried moving the

        Collider2D[] GroundOverlap = null;

To the start statement, still nothing. Any help is appreciated!

For OverlapCircleNonAlloc() you need to allocate an array with the maximum number of elements you want returned.

Collider2D[] GroundOverlap = new Collider2D[25];

In addition the way you are doing it doesn’t make sense for NonAlloc. That is, you appear to be defining ‘GroundOveralp’ in the function. To get the benefit of NonAlloc() GroundOverlap as a class instance variable (typically private and outside of any functions in the class). That way, each time you call the function, you are reusing the same memory.