2D colliders are not working as expected.

I’m having an issue with my 2D game’s code…

Collider2D[] colliders = Physics2D.OverlapCircleAll(wallspawn.transform.position, 1f, 0);
                    if (colliders.Length == 0)
                    {
                        CmdWallSpawner();
                    }
                    else
                    {
                        Debug.Log(colliders);
                    }

This should see if there are any objects on the default layer, where I put my building blocks, and other collidable objects… but It still allows me to place an run the CmdWallSpawner() function even if there is something in that area…

4681934--441110--upload_2019-6-24_16-52-3.png

Hello.

Try this:

Collider2D[] colliders = Physics2D.OverlapCircleAll(wallspawn.transform.position, 1f,  LayerMask.GetMask("Default"));

instead of

Collider2D[] colliders = Physics2D.OverlapCircleAll(wallspawn.transform.position, 1f,0);

Zero is index of Default layer only in inspector (Dunno why). The real index of Default is 1 but GetMask("Default") is the best solution for this.