How can i play a particle effect after my gameobject has been destroyed?

i have this explosion particle effect childed to a gameobject but when i destroy the gameobject
the particle effect is destroyed too, is there a way i can play the particle effect at the same time it’s destroyed?
this is how my code looks like at the moment

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerDeath : MonoBehaviour
{
    [SerializeField] Collider[] deathCollider = new Collider[2];   
    [SerializeField] GameObject ball;
    [SerializeField] ParticleSystem deathVFX;

    private void Awake()
    {
        deathVFX.Stop();
    }

    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
       
    }

    public void OnTriggerEnter(Collider deathCollider)
    {
        Instantiate(deathVFX, transform.position, transform.rotation);
        // deathVFX.Play();
        Destroy(ball);
    }
}

You have to unparent the particle effect’s GameObject before the parent is destroyed.

1 Like

Or you could remove the parenting completely, and create a pool of particle effects.
Each time a GameObject gets destroyed, pick a particle effect from the pool and set it’s position
to the position of the destroyed GameObject and let it play its magic. When it’s done, reset it in the pool.
This way, a lot of GameObjects get saved from instantiating and destroying, which is bad for performance.

1 Like

Yep, somehow make the particle effect a separate object. You could unparent or pull one from a pool as stated above, or you could instantiate/destroy it.