Problem with destroying instanciated enemies

I have some code to destroy an object when it gets hit by a bullet, and a simple enemy prefab.
If I put a few of these in the scene in the editor, they will be destroyed just fine. But if they are instantiated by another object they won’t interact with the bullets, even though the prefab is the same.

The code related to destroying the enemies:

public GameObject explosion;

void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Bullet")
        {
            Instantiate(explosion, transform.position, Quaternion.identity);
            Destroy(other.gameObject);
            Destroy(this.gameObject);
        }
    }

I don’t know why this only works for manually created enemies, if anyone could explain why that would be great :slight_smile:

maybe check that prefab is updated. delete prefab and create new with object in editor that works. also how you instantiate may help as this code seems fine

Replaced the prefab, still not working. Here’s the code to instantiate:

private int number = 0;
    public GameObject enemy;

    void Update ()
    {
        number = Random.Range(1, 100);
        if (number == 50)
            Instantiate(enemy, new Vector3(0, 0, 185.0f), Quaternion.identity);
    }

Please excuse the sloppy random enemy spawner thing, it’s still a test
The enemy gameobject is the one we were talking about earlier, and the one I have replaced in the editor

It’s working now, not sure what I did. A lot of Debug.Log but the only code I changed was the 185.0f to 160.0f so it could be that the bullets go so fast, they kind of skip over the area around the enemy at 185.0f but this is basically just speculation. Gonna make the hitbox longer just in case.