How can I destroy clone object after collision?

Hello.

I don’t know why this doesn’t work. It works for my bullet decal but not for a projectile.

using UnityEngine;
using System.Collections;

public class ChargedBulletCol : MonoBehaviour {

    public GameObject DestroyParticles;

    void OnCollisionEnter(Collision col) {
       
            Debug.LogError("Collided");
            DestroyParticles.SetActive (true);

        Destroy (transform.parent.gameObject);  
        }
}

I want to destroy the clone object after it hits something.

You’re trying to destroy the parent of the object the above script is attached to. You say it works when the script is attached to a bullet decal, but not when it’s attached to a projectile.

Maybe that’s because the bullet decal has a parent object but the projectile does not?

If that’s not the case, you may want to provide some additional details…

None of them have parents :confused:

So your getting the error msg “Collided”, but no luck with the Destroy?

Yes

transform.parent.gameObject

attempting to access the gameObject of something that doesn’t exist should be generating a NullRefError in the console…

It does not. Is the Destroy function even being called?

The projectile is a clone though, I dont know if that matters.