Physics.OverlapSphere not detecting colliders

I’ve seen other posts about problems with Physics.OverlapSphere not detecting colliders, but nothing seems to get mine to work.

My first question is, which types of colliders does OverlapSPhere detect? I am using Kinematic Rigidbody trigger box colliders 2d attached to a prefab object. I read in one post that OverlapSphere does not detect triggers, so I unchecked “Is Trigger”, but that made no difference. Then I read somewhere that in Unity 5.0 it will detect triggers, so I updated from 4.6 to the latest 5.0, no change. I used OnDrawGizmos to make sure the sphere was positioned correctly, and that is definitely not the problem.

Anyway, here is the relevant code, hopefully someone will spot what noobish error I have made:

I have an enemy-spawning script that spawns a group of prefabs at either end of the game screen. For a simple test to try to get this working, I have it spawning two instances of the same prefab at one end of the game screen:

public class enemySpawner : MonoBehaviour {

public GameObject brownOrc;
public GameObject redOrc;

Vector3 brownSpawn = new Vector3(5, 10, 0);
Vector3 redSpawn = new Vector3(5, 1, 0);


// Use this for initialization
void Start () {
	orc_stats newOrc;
	GameObject go1, go2, temp;
	orcTeam brownTeam, redTeam;
	int numBrown, numRed, i;
	
	go1 = GameObject.Find("brown team");
	brownTeam = (orcTeam) go1.GetComponent(typeof(orcTeam));
	numBrown = brownTeam.get_numOrcs();
	
	go2 = GameObject.Find("red team");
	redTeam = (orcTeam) go2.GetComponent(typeof(orcTeam));
	numRed = redTeam.get_numOrcs();
	
	for (i = 0; i < numBrown; i++) {
		temp = Instantiate(brownOrc, brownSpawn, Quaternion.identity) as GameObject;
		newOrc = temp.GetComponent<orc_stats>();
		newOrc.teamName = "brown";
		brownSpawn.x++;
	}
	
	for (i = 0; i < numRed; i++) {
		temp = Instantiate(redOrc, redSpawn, Quaternion.identity) as GameObject;
		newOrc = temp.GetComponent<orc_stats>();
		newOrc.teamName = "red";
		redSpawn.x++;
	}
}

}

Then I have another script that, in Update() attempts to see if there are any Orcs within a certain range:

// Update is called once per frame
void Update () {
	Collider[] targs = Physics.OverlapSphere(transform.position, 5.0f);
	
	print("xxx-" + targs.Length);
}

No matter what I do, targs.Length is always 0.

Try this

I think the issue is your 2D colliders.