Destroy Parent, keep child

I'm trying to do an effect where when an object is picked up, a particle effect is transmitted, but the parent object vanishes when the effect occurs, or just before.

I can see lots of information on how to destroy child objects but not the parent.

Note, there are many of the same objects in the game, and they are all named the same because they have been duplicated throughout.

thanks for information on this topic


Just detach the child before deleting the parent. If your script is attached to the Emitter GO:

void OnPickup()
  GameObject objectToDelete = transform.parent;
  transform.parent = null;

You could also just delete the whole object and spawn a new GO containing the emitter.

okay, I tried the above, but my lack of time with Unity confused me. I tried to stay on tack with what I had already written not knowing how to implement the suggested. This below is working.

function OnTriggerEnter(hit : Collider) {

if (hit.gameObject.tag == "STUFF" ) 


var blah : GameObject = hit.gameObject; //need to identify the name of object so I can detach later

    //before detaching turn on the particles the hit.gameObject.GetComponentInChildren is the missing piece
    // that will frustrate for hours... keyword hit.
var emitter : ParticleEmitter =   hit.gameObject.GetComponentInChildren(ParticleEmitter);
    if (emitter)





I set my particle effect up to be parented to the "STUFF" that gets picked up, and then set it to "One Shot" so that it plays once through the effect, I don't remember having to do this before (probably because I have used destroy to destroy objects emitting effects previously) but I also have to turn on autodestruct in the particles to make them go away after playing once.