• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Particles and Memory Leaks

T

Tribow

Guest
I've been facing this issue for a long time in my game and it's about time I asked for some help.

It's a bullet hell game that has A LOT of particles in it since I like the effect of lasting debris when an enemy is destroyed. I'm pushing the limits of how much particles I can have around, however, I don't really know what I'm doing since I'm a little new to particles.

Most particles are created in the destroy events of the objects. Every time the room changes I've written code that should destroy the particle systems, types, and emitters that exist. Unfortunately though it doesn't seem to work.
I have a feeling I'm approaching this in a very wrong way so I came here to ask, how you approach wiping out any memory of particles that exist every time you change rooms and is it wrong to create the systems in the destroy events of objects?
 

NightFrost

Member
It shouldn't be necessary to destroy them, and inadvisable if you're going to need them later, as you must spend time re-declaring them again. AFAIK you just need to call part_particles_clear to remove all current particles in the system, and if you have stream emitters do part_emitter_clear as well (or they keep spawning particles that will be destroyed next step because the system was cleared). Systems, particles and emitters themselves don't eat CPU time (or eat trivial amounts?) if no particles are being emitted.
 
T

Tribow

Guest
I tried your suggestion, but it doesn't seem to work, either that, or I'm doing this wrong.
 
S

Silicon Sorcery Studios

Guest
If you are creating ur particles in a destroy event then where are the particles (themselves) being destroyed and freed from memory?

Or are you simply calling them into action during the destroy event?

The idea is to write ur particfle code in a seperate object and then use a timer or a 'if !instance_exists(obj_projectile)' to kill the particle; along with part_particle_clear and part_emitter_clear.
 
T

Tribow

Guest
The creation of the particles were made in destroy events of parent objects, but the object that has the code to destroy the particles every time the room changes is the player object.

I'm assuming that's the wrong way to do it, but I'm not sue how to do it right.
 

JasonTomLee

Member
Hey @Tribow ! I've been working on some particle scripts for an asset recently so I'll tell you a few tricks I've learned.

You don't necessarily have to destroy and remake the PartSystems every time you switch rooms. Simply clear the ParticleSystem using the part_particles_clear( ps ) when you swap rooms. And use a global ParticleSystem that is initialized ONCE at the start of the game!

For Emitters, you should definitely clear&destroy them when they aren't being used OR if new ones are initialized at the start of a room. Keep all the creation/deletion code in a separate Controller object to not confuse yourself~ (I like to use oGame to organize general room & debug code).

If you would simply like to burst particles, try using the part_particles_create script. It doesnt require any emitter so that should save you from a headache ahha
 
T

Tribow

Guest
So if I understand correctly, the particle system has to be created in a control object. I only need part_particles_clear, and creating particles in destroy events are a nono.

A new problem arises with this information though. All of the enemies in the game use the same particle system, however, depending on the enemy the particles can be different colors. I did this by making the variables pcolor and pcolor2 in the create events of the enemy objects.

In the parent object of the enemies I had the creation code to the particles and emitters in the destroy event where in the particle_type_color code I set the colors to the variables I made, however, now I know this method won't make it possible to clear the particles.
I want to try to avoid making particle systems for every enemy in the game (same actually goes for bullets as well since they make particles). I hope there's a way of doing this.
 
T

Tribow

Guest
Bringing back this thread with another question about particles!
Thanks for the help so far, the particles work the way they should now, but a weird thing happens.

I use part_particles_clear and part_emitter_clear every time I change rooms in the step event of the player object.
Whenever the player object is destroyed and respawned later, particles stop working.
Does anyone have an idea as to why?

(I know that it isn't telling the game to clear particles/emitters every frame because the code to go to the next room is in the same block as the particle clearing code. It would go to the next room every frame if that was the case)

((particles are not created in the player object, they're created in a control object))
 

Bingdom

Googledom
Do you perform room_restart or room_goto(room) when the player dies? If so:
Make sure the only time you initialise the particles would be in a "Game Start" event (make sure the object exists in the first room), or the create event if the controller object is persistent.
 
T

Tribow

Guest
I actually fixed the issue by moving the initializing to the create event to the step event, so my final question would be if that's a bad idea? I never heard of anyone creating the particle system in the step event before.

I did move the controller object and initialized the particles at the start of the game, but the issue still happened until I moved it to the step event.

EDIT: Actually ignore this, thanks everyone for the help! I understand how to do this now!
 
Last edited by a moderator:

NightFrost

Member
I should add a correction: I said above that if you are streaming particles constantly with part_emitter_stream you need to use part_emitter_clear to stop them (which btw also resets any part_emitter_region you may have declared for the emitter). I happened to look at one of my emitter builds and noticed this is in fact not necessary. You only need to use part_emitter_stream for the emitter again and set the number of particles to zero. This of course will not remove particles already emitted - as I mentioned above that's what part_particles_clear does.
 
Top