OnCollisionEnter doesnt work when instantiated

Hi,

I have this strange problem with collision detection. The “OnCollisionEnter” works fine if it’s attached to a gameobject which I put into the Scene manually; however if I want to instantiate the same gameobject’s prefab (example: by pressing a button) the gameobject prefab is instantiated, but the collision doesn’t work anymore.

WTH? Help please p.s. I have tryed the OnCollisionStay, but it didnt help :(.

The code (enemy):

var BoomExplosion : GameObject;

function OnCollisionEnter (TriggerEnter : Collision)
{
if(TriggerEnter.gameObject.name == “BoomExplosion(Clone)” || TriggerEnter.gameObject.name == “BoomExplosion”)
{
Instantiate(SpawnExplosion, gameObject.transform.position, gameObject.transform.rotation);
Destroy(gameObject);
}
}

what happened to friendly unity community. 1 year ago, I would get 10 answers by next day, now… its like commentary.

Even then you wouldn’t have gotten one as the code is correct but a bit missleading (triggerenter but its a collision event) and you don’t offer any information basing on which one could help you.
All we have on our end here is “that you have a problem” but thats really about it.

Also you have not mentioned anything else so its to assume that the problem is not instantiate but the prefab, for example you expect the OnCollisionXX / OnTriggerXX on the wrong game object (they will be sent up all the way in the hierarchy to the first rigidbody found and alike)