Raycast2D hits itslf

Ok so I am probably just doing something wrong since the 2D physics is all new. But what I am trying to do is fairly simple. Run a raycast from a square with a Rigidbody2D and BoxColider2D attached. I am using the code:

//Trace Down
HitInfo = Physics2D.Raycast(transform.position, -transform.up, 1);
	if(HitInfo.collider != null)
	{
		Debug.Log("HIT " + HitInfo.collider);
		if(HitInfo.collider.GetComponent(Hull) != null)
		{
			NewLinks.Add(HitInfo.collider.GetComponent(Hull));
		}
	}

Problem is according to that log it is hitting itself. I can’t use a mask because it is looking for other squares that are just like it so if it cant see itself it also would not be able to detect other like squares.

With a normal 3D raycast this wouldn’t be a problem since the ray is originating inside the mesh faces and thus would not count the collision.

Any ideas?

A bit of a hack, but you can turn the collider off and back on for the current object around the Raycast2D:

collider2D.enabled = false;
HitInfo = Physics2D.Raycast(transform.position, -transform.up, 1);
collider2D.enabled = true;

You could use RaycastAll or RaycastAllNonAlloc to get all of the collisions of the ray or you could offset the start of your ray by the size of the existing collider.