Destroying clone particles

I’m trying to get my game to destroy the particle clones however when I use the Destroy() function on the gameObject i get an MissingReferenceException error

So how do I get rid of these particles once I instantiate a new one?

You should probably post the relevant snippet of code. What is that .gameObject you are destroying? The thing making the particle? The particle system game object itself? Something else?

Basically you want to Instantiate() the particle system, which ought to go on a fresh GameObject, and then destroy it when you’re done.

This is the code I have that is currently spawning the particles when the player is doing a double jump. What I don’t know how to do is to destroy the particle once it has spawned and then be able to spawn another one.

public GameObject particle;

       void Update()
    {
       
        if ((grounded || !doubleJump) && Input.GetButtonDown("Jump"))
        {
            rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, 0);
            rigidbody2D.AddForce(new Vector2(0f,jumpForce));
            audio.Play();

            if (!grounded && Input.GetButtonDown("Jump"))
                    Instantiate(particle,transform.position, transform.rotation);

           

            if (!doubleJump && !grounded)
                doubleJump = true;
        }
    }
}

You need to keep a reference of the instantiated object and destroy it.

ParticleSystem go = Instantiate(particle,transform.position, transform.rotation) as ParticleSystem;

Destroy(go.gameObject, go.duration);

Something like that, I’m playing can’t help you more for now

Adding this gives me this error

NullReferenceException: Object reference not set to an instance of an object
Movement.Update () (at Assets/Scripts/Movement.cs:49)