Particle FX Question?

Godot Version

4.2.2

Question

Hello all,

I have created a particle effect it’s not great to would like to implement it into my attempt at a game.

So, lets just pretend the particle effect is perfect, the colours are great and everything is hunky-dory. Now, how do I use it? In the tutorial I watched the only thing they did was create the particle FX or code on how to run it just the once. The particle effect is just a standalone scene, with only the one node, not associated with anything. I want it to go off when the bomb explodes - at which time the particle effect plays once on the rock that is to be supposed to be destroyed by the bomb and then disappears - hence playing just the once.

As always here is a big thankyou in advance if you can help.

Although truthfully this is an even bigger thankyou in advance, I never thought I would get to the moment where I could drop a bomb and make it so part of the “scenery” would be destroyed this particle effect is just icing. Only one thing remains now wall jumping something that I found quite complicated in Unity and may be beyond me with my current skills in Godot.

I must take the time to say ‘thankyou’ to everyone who has helped thus far, it really was appreciated :sunglasses: :pray:.

Regards.

I’ll assume you already figured out how to run code when the bomb explodes and saved your particle effect under “res://particle_effect.tscn” with the one_shot property enabled.

Then it’s just calling spawn_particles with the bomb’s position once:

const PARTICLE_EFFECT = preload("res://particle_effect.tscn")

func spawn_particles(pos: Vector2):
    var particle_effect = PARTICLE_EFFECT.instantiate()
    add_child(particle_effect)
    particle_effect.global_position = pos
    particle_effect.emitting = true
    particle_effect.finished.connect(
        particle_effect.queue_free
    )
1 Like

Don’t assume anything when I’m involved :grin:.

I’ll need to find that one_ shot property the tutorial I was using and what was on screen with 4.2.2 was completely different and caused me apoplexy trying to find everything turning a quick 4 minute tutorial into a 1 hour ordeal.

But the I should be able what you said and get it working - should being the operative word :stuck_out_tongue:.

I report back when I get to it first thing tomorrow.

Thanks for replying :sunglasses:.

Keep in mind, though, that there are both GPUParticles2D and CPUParticles2D, and while the former were refactored in 4.2, the latter won’t be – so their feature sets differ quite a bit now! That being said, the one_shot property can be found under the “Time” category in both of them. :slight_smile:

1 Like

Hi, sorry if I ask something OT, but could this code snippet be used nearly “as it is” for instancing a water splash when the Player enters in water?
Thanks

Yes. :slight_smile: The logic will always be the same, while the actual visuals are determined by the scene with the particle effect.

1 Like

Thankyou that made it so much easier to find. It wasn’t mentioned in the tut.

Well that wasn’t fun. I was making the final change in passing the position to the function, and Godot told me that the explosion scene was invalid/corrupt.

Back to the tutorial again to waste more time finding the parameters.

Right had numerous problems since I last posted - lost the project completely, was luckily able to restore from a backup I made earlier.

Anyway, I am trying to spawn the particles properly and in the proper spot and it isn’t working.

Firstly the particles are set to “One Shot” yet they are repeating and they are spawning in the wrong spot dead centre of the game screen and constantly repeating after they are instantiated.

The are re-spawning constantly, once they are activated and I am getting the following errors when the game is run:

I can supply any information or code needed to track down the error.

If you can help, here is a huge thankyou in advance.

If you can, just upload your entire project folder somewhere and link it here.

The first error is telling you that your particle_explosion scene (ending in ‘.tscn’) is referencing a particle_explosion script (ending in ‘.gd’) which seems to not exist (anymore?).

The second error hints at the fact that your particle_explosion scene seems to include some resource which includes another resource from this scene, resulting in an infinite loop.

Both of these errors will be a lot easier to spot with access to the full project.

The game scene is invalid/corrupt again.

For the fourth nope, 5th nope, 6th time today :face_with_symbols_over_mouth:

Right, I have found what is causing the problem I can run the game up until I reach the point before I add this code. Of course, I get an error saying there is no function because it hasn’t been added yet.

After adding the code the game actually runs until I shut down Godot and try and reopen at which I am told that there is an invalid/corrupt scene with the FX component, and then when I try to reopen the game scene I am them told that it is corrupted as well. This is the code

extends CPUParticles2D

const PARTICLE_EFFECT = preload("res://scenes/particle_fx.tscn")

func spawn_particles(pos: Vector2):
	var particle_effect = PARTICLE_EFFECT.instantiate()
	add_child(particle_effect)
	particle_effect.global_position = pos
	particle_effect.emitting = true
	particle_effect.finished.connect(particle_effect.queue_free)

Like I said, it functions, gives me those two errors in the debugger then won’t reopen properly afterwards. I am able to reproduce it now as I have a backup made just before that point. This is the error massage produced when I reload the Godot project:

You said you need to see the code, but, where could I upload it to. I don’t think I have any cloud source that I could upload to, would you be able to recommend some that i could look into?

Thankyou and Regards.

Right when I changed to code to this in the rock destroy function which I found after going through a number of tutorials:

@export var particle_fx1:PackedScene;

At which point I need to drag the particle effect scene into it
And this code later:

    var rock_position = Vector2();
	rock_position.x = 0; #global_position.x;
	rock_position.y = 0; #global_position.y;
	
	timer_2.start() #don't ask, just don't
	#particle_fx#
	var effect_instance :CPUParticles2D = particle_fx1.instantiate()
	effect_instance.global_position = rock_position;
	add_child(effect_instance);
	effect_instance.emitting = true;
	effect_instance.finished.connect(effect_instance.queue_free);

Everything seemed to work no errors and the project wasn’t going invalid/corrupted anymore. I have no idea what a packed scene is, and at this point I really don’t care.

I give up, I don’t know why this code worked and the other code didn’t, I am just mentally and physically drained at this point. That’s about 11 hours work to get this far :weary:.