OnTriggerEnter2D working only on original prefab and not on its copies

TL;DR: OnTriggerEnter2D works perfectly with one instance of a sprite. But it starts to work sporadically if I duplicate said sprite in the scene.

Hi all,

I have a script that should count how many aliens the player has encountered.

To do so I have this set up:

  1. a player sprite prefab with a Box Collider 2D and a Rigid Body 2D attached to it (see image below)
  2. an alien sprite prefab with a Box Collider 2D with Is trigger set to true and a Rigid Body 2D attached to it (see image below)
  3. a script attached to the alien sprite that counts how many times the player passed by an alien (see script)
  4. I’m working on Unity 4.6.3f1 for Mac

The script counts all encounters when I have only one alien prefab in the scene, it counts them no matter how fast the players moves, or how many times per second it passes by the alien. As soon as I duplicate the alien’s prefab (Command D), the script counts only some of the encounters. It seems to do it sporadically on all sprites, the original and copies.

I’ve already tried to:

  1. Delete and recreate Rigid Bodies 2D and Box Colliders 2D on both the alien and the player
  2. Change the collision detection from Discrete to continuos on both sprites
  3. Rename the alien copies
  4. Not use prefabs
  5. I’ve all layers checked under Edit > Project settings > Physics 2D
  6. Used this code to check if triggers work: Debug.Log("Trigger: " + collider2D.isTrigger);
  7. Restart Unity

Any help is much appreciated, thank you.

The code

using UnityEngine;
using System.Collections;

public class Alien : MonoBehaviour {
	private int encounteredAliens;

	void OnTriggerEnter2D(Collider2D other)
		if (other.CompareTag ("Player")) {
			Debug.Log ("encounteredAliens: " + encounteredAliens);

The player’s prefab inspector

The alien prefab inspector

your counter is on each alien and starts each time by zero. It counts for each alien the collisions with a player. Don’t know if this is what you wanted. If you want to count the collision for the player with each alien, you should put the counter on the player.