'Unity - How to make trail renderer lasts after game object destroyed?

I'm trying to make a gun on unity, but I'm having a problem with trail renderer. I made this code to destroy the bullet when it collides, but when it is destroyed the trail stops in the air and after that time trail renderer it disappears, i want the trail to continue and slowly disappear.

bullet trail stopped in the air, and then disappears

I tried to do something but didn't work, this is my code.

    public TrailRenderer Trail;

    private void Awake() {
        Trail = GetComponentInChildren<TrailRenderer>();
    }

    void OnCollisionEnter(Collision coll) {
        Debug.Log("aaa");
        Destroy(gameObject);

        Trail.transform.parent = null;
        Trail.autodestruct = true;
        Trail = null;
    }

I appreciate any suggestions.



Solution 1:[1]

Have you tried to change order? You destroy the object before you change the parenting ;)

Try

Trail.transform.parent = null;
Trail.autodestruct = true;

Destroy(gameObject);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 derHugo