GML How to stop a particle system properly [SOLVED]

Carloskhard

Member
First of all: I've already read multiple threads about this in this forum but none of them work so I need help.
I created a particle system inside my main object like this:

//Particle System
part_sys_chispas = part_system_create();
part_system_depth(part_sys_chispas,-11);
//Particle
part_chispas = part_type_create();
//part_type_sprite(partPower,spr_humo,false,false,false);
part_type_shape(part_chispas,pt_shape_disk);
part_type_scale(part_chispas,0.5,0.5);
part_type_size(part_chispas,0.5,1.2,-.07,0);
part_type_alpha2(part_chispas,1,.5);
part_type_colour2(part_chispas,c_yellow,c_red);
part_type_life(part_chispas,room_speed/1.8,room_speed/2);
part_type_blend(part_chispas,false);
//Particle Emitter
part_emit_chispas = part_emitter_create(part_sys_chispas);
*chispas means sparkle in spanish..yeo I write half and half spanish english in my code jaja

part_emitter_region(part_sys_chispas,part_emit_chispas,x-70,x+70,y-70,y+70,ps_shape_ellipse,ps_distr_gaussian);
if (hp < 4) particulas = 3;
else if (hp < 7) particulas = 2;
else if (hp < 10) particulas = 1;
else particulas = 0;
part_emitter_stream(part_sys_chispas,part_emit_chispas,part_chispas,particulas);
*particulas means partciles and in this code I check for the hp of the object to create more or less particles

But then I destroy event of that object I do this:

Code:
part_particles_clear(part_emit_chispas)
part_type_destroy(part_chispas)
part_emitter_clear(part_sys_chispas,part_emit_chispas)
If I just use:
Code:
part_particles_clear(part_emit_chispas)
part_emitter_clear(part_sys_chispas,part_emit_chispas)
doesn`t work and particles keep being generated.
And if I add the line "part_type_destroy(part_chispas)" the game crashes automatically when the line executate...

What is wrong? Thanks
 
Last edited:
R

Raphael Caloz

Guest
You must use part_system_destroy(ind);
where ind is the index of you particle system (and not of the emitter).
 

Toque

Member
part_system_destroy(ind); does normally work. Something else in the code that might be causing crash?
 

Bart

WiseBart
Just an idea, but have you tried destroying them in the following order: emitter, system, type?
The emitter likely can't exist if the system it's in is destroyed. Likewise, if you destroy the particle type while there is still a need for the type to exist (part_particles_clear and part_emitter_clear may not be sufficient..), you might get an error.
 

Carloskhard

Member
Just an idea, but have you tried destroying them in the following order: emitter, system, type?
The emitter likely can't exist if the system it's in is destroyed. Likewise, if you destroy the particle type while there is still a need for the type to exist (part_particles_clear and part_emitter_clear may not be sufficient..), you might get an error.
Thanks for the idea, what you say makes a lot of sense but I already tried different orders and also using each individual funtion alones but that does not work sadly
 

Bart

WiseBart
I think I get it now. You're calling part_emitter_stream, which streams particles continuously.
It's normally sufficient to call this function once, since it basically tells the emitter to 'start streaming' a certain amount of particles of a certain type.
In the Destroy event, you destroy the particle type, but you don't tell the emitter to 'stop streaming' particles of that type.
So you probably have two solutions:
  • Replace part_emitter_stream in the Step event by part_emitter_burst - the difference is that stream is continuous, burst is single-shot
  • Use part_emitter_stream to set the number of particles streamed to 0 (or just remove the emitter first, which should work according to the manual - "The above code will stream 1 particle every step of the game until the emitter is destroyed or the stream set to 0.")
EDIT
Wait, I just read that part_emitter_clear is supposed to be the 'stop streaming' command.
What might be the solution in that case is to clear the emitter before destroying the particle type.
 
Last edited:

Toque

Member
I used

Part emitter stream ()
Part emitter destroy all (). It did stop it.

I can confirm as I just did it. But it’s in a step event so maybe it’s destroying it every step?

So I changed in step event to:
part emitter burst ()
Part emitter destroy all ()


That’s stops it as well. Probably a better way in a step event!!

Thanks. @Bart

I hope original poster figured it out.
 

Carloskhard

Member
Hey I got a solution working finally!

I first try going the other way using single particle spawning with "part_particles_create(part_sys_chispas, random_range(x-45,x+45), random_range(y-45,y+45), part_chispas, -particulas)" and that worked, however that code can't offer some useful stuff that can be done with emmiters, so I had a temporal fix.

I spent some time trying different code. Part particles clear was just erasing the existing particles at screen but the streaming continue after so I keep testing and finally "part_emitter_destroy(part_sys_chispas,part_emit_chispas)" was able to destroy the emmiter once for all :D

Seems like these functions weren't working 'cause I was putting the name of the emmiter when I was supposed to enter the name of the system.

For some reason that I can't understand yet, using "part_emitter_stream(part_sys_chispas,part_emit_chispas,part_chispas,0);" at the destroy event doesn't stop the streaming... That's weird cause I don't thhink the step event is supposed to act after the destroy event,right? So I don't think the streaming is reseting after that line..but neither stopping. (I hope I'm expressing this clear, sorry for my bad english).

Last thing to talk about and solve is about using "part_emitter_burst". This function is just creating particles everytime is called, but doesn't create a stream, so when the object gets destroyed the particles stop being created. Cool right?¿! ... Not so much when I realized that after dying and starting again, propulsion particles (which I was creating using emmiter brust) don't render correctly. Compare how particles change every time the spaceship dies and start again:


**Life, ups :oops:

What do you think may be causing this?

Also sometimes when I exit the room and come back as a new game the particles keep being rendered at that spot so..not sure what is up with that.I guess I have to delete the emmiter even tought is a brust emmiter when changing room

Thanks @Toque and @Bart for the help so far :)
 
Last edited:

Bart

WiseBart
For some reason that I can't understand yet, using "part_emitter_stream(part_sys_chispas,part_emit_chispas,part_chispas,0);" at the destroy event doesn't stop the streaming... That's weird cause I don't thhink the step event is supposed to act after the destroy event,right? So I don't think the streaming is reseting after that line..but neither stopping. (I hope I'm expressing this clear, sorry for my bad english).
Is the Destroy event executed? Are you perhaps using a persistent room or object?
Instances of a persistent object move between rooms and don't have their Destroy event executed when moving between rooms. They do execute Room Start and Room End events instead. Instances in a persistent room don't get destroyed either, but they also have the Room Start and Room End event executed.
This, combined with GM's particle system, might give unexpected results like the ones you're encountering.
It's not because you're still seeing particles that a Step event is still being executed. It might be the result of a previous call to part_emitter_stream.
That's because particle systems are global, which means you can get similar issues as when you're using global variables. Even in a different room.
Also sometimes when I exit the room and come back as a new game the particles keep being rendered at that spot so..not sure what is up with that.I guess I have to delete the emmiter even tought is a brust emmiter when changing room
This is likely an example of the above.

Could you post the code you're currently using? It's hard to tell where the issue is without code.
 

Carloskhard

Member
Is the Destroy event executed? Are you perhaps using a persistent room or object?
Instances of a persistent object move between rooms and don't have their Destroy event executed when moving between rooms. They do execute Room Start and Room End events instead. Instances in a persistent room don't get destroyed either, but they also have the Room Start and Room End event executed.
This, combined with GM's particle system, might give unexpected results like the ones you're encountering.
It's not because you're still seeing particles that a Step event is still being executed. It might be the result of a previous call to part_emitter_stream.
That's because particle systems are global, which means you can get similar issues as when you're using global variables. Even in a different room.
This is likely an example of the above.

Could you post the code you're currently using? It's hard to tell where the issue is without code.
I see, I'll try reseting everything when restarting the room and I will share my results here once I get something!

*Edit: So far I've used "part_emitter_destroy(fuego,fuego_emitter)" to destroy the emitter of the propulsion fire at destroy event and "end room" event. However, every time I respwan (this is made restarting the room) particles get mess up as you saw on the gif, but just for the propulsion particles... maybe it has something to do with this one being the onle brust emitter?
 
Last edited:

Toque

Member
Hey I got a solution working finally!

I first try going the other way using single particle spawning with "part_particles_create(part_sys_chispas, random_range(x-45,x+45), random_range(y-45,y+45), part_chispas, -particulas)" and that worked, however that code can't offer some useful stuff that can be done with emmiters, so I had a temporal fix.

I spent some time trying different code. Part particles clear was just erasing the existing particles at screen but the streaming continue after so I keep testing and finally "part_emitter_destroy(part_sys_chispas,part_emit_chispas)" was able to destroy the emmiter once for all :D

Seems like these functions weren't working 'cause I was putting the name of the emmiter when I was supposed to enter the name of the system.

For some reason that I can't understand yet, using "part_emitter_stream(part_sys_chispas,part_emit_chispas,part_chispas,0);" at the destroy event doesn't stop the streaming... That's weird cause I don't thhink the step event is supposed to act after the destroy event,right? So I don't think the streaming is reseting after that line..but neither stopping. (I hope I'm expressing this clear, sorry for my bad english).

Last thing to talk about and solve is about using "part_emitter_burst". This function is just creating particles everytime is called, but doesn't create a stream, so when the object gets destroyed the particles stop being created. Cool right?¿! ... Not so much when I realized that after dying and starting again fire particles (which I was creating using emmiter brust) don't render correctly. Compare how particles change every time the spaceship dies and start again:




What do you think may be causing this?

Thanks @Toque and @Bart for the help so far :)
If you place the part_emmiter_burst in the step event I believe it will "stream".
When you destroy that object and want to end the particles I would place the
Part_emitter_ destroy all () in the destroy event and I would think that would stop it.
Im learning the particle system as well so by all means no expert.
 

Carloskhard

Member
Sorry it’s beyond my skill.
Hey man! Don't need to apologize for trying to help! I appreciate every bit of help a lot! :D

I finally solved the problem of the particles rendering weirdly and the problem was so stupid I don't even know how I didn't saw it jajaja

When I was calling the emitter to burst I was using "part_emitter_burst(fuego_sys,fuego_emitter,XXX,1)" and in "XXX" I put the system name again instead of the particle type, which resulted in a random partycle type being rendered each time (I don't know how it was even working jajaja)

Sooo.. PROBLEM SOLVED!
If anyone encounter similar problems feel free to comment I'll explain more details about how I solved this.
Thanks everyone for the help :):)
 
Top