RaycastHit returns object without collider, in wrong layer

I have a Game Object with a script that has a function which raycasts four times around it to assess the Objects around it (Essentially, I have box colliders set up in a grid that check each other in a function). While these raycasts usually go through fine, there is a problem where the raycast keeps picking up certain objects (Walls, as planes in between the colliders) which have mesh collider turned off, and the raycast is set to pick up only layer 10, while these walls are on layer 12. Why is this happening, and how do I fix it?

With seemingly irrelated code removed, this is what I’m doing. print(colliderMapTile) returns an instantiated Prefab with it’s collider turned off with it’s layer set to 12.

var layermask = 1 << 10;

function updateSurroundingRooms(){
	var	cardinalDirection = new Vector3[4];
	cardinalDirection[0] = transform.TransformDirection (Vector3.forward);
	cardinalDirection[1] = transform.TransformDirection (Vector3.right);
	cardinalDirection[2] = transform.TransformDirection (Vector3.back);
	cardinalDirection[3] = transform.TransformDirection (Vector3.left);
	for(var i : int = 0; i < 4; i++){
		var hit : RaycastHit;
		var colliderMapTile : GameObject;
		if (Physics.Raycast (transform.position, cardinalDirection*, hit, layermask)) {*
  •  	colliderMapTile = hit.collider.gameObject;*
  •  	print(colliderMapTile);*
  •  	colliderMapTile.GetComponent("MapTileColliderBehaviour").roomChange();*
  •  }*
  • }*

There is no overload for

Physics.Raycast (origin: Vector3, direction: Vector3, hitInfo: RaycastHit, layerMask: int)

In your code it takes the bitmask as the distance parameter.

[static function Raycast(origin: Vector3, direction: Vector3, hitInfo: RaycastHit, distance: float, layerMask: int): bool;][1]

Replace it with

Physics.Raycast (transform.position, cardinalDirection*, hit, yourDistance, layermask)*

btw. if you use var mask : LayerMask on a component you should see the layermask dropdown in the inspector to configure layermasks easily. Anyway that’s how it’s done in c# public LayerMask mask and I guess it also works in us/js.
[1]: Unity - Scripting API: Physics.Raycast