godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.88k stars 20.15k forks source link

GPUParticles don't emit finished signal when oneshot is set true in gdscript #93991

Open JUSTCAMH opened 2 months ago

JUSTCAMH commented 2 months ago

Tested versions

System information

Godot v4.3.beta2 - Windows 10.0.19045 - GLES3 (Compatibility) - NVIDIA GeForce RTX 3070 (NVIDIA; 31.0.15.3619) - 11th Gen Intel(R) Core(TM) i7-11700K @ 3.60GHz (16 Threads)

Issue description

When setting oneshot to true on a GPUParticles2D node, the particles visually stop emitting some time later as expected, however the 'finished' signal is not emitted. This does not occur with CPUParticles2D. I have not tested this for 3D particles, but I presume that this also applies to the GPUParticles3D.

Steps to reproduce

Minimal reproduction project (MRP)

particles-finished-bug.zip

JekSun97 commented 2 months ago

I confirm this problem

4X3L82 commented 2 months ago

I reported something similar in #93546.

patwork commented 2 months ago

Perhaps this is related https://github.com/godotengine/godot/pull/76859#issuecomment-1769504893

❗ UPDATE: try using restart() instead of emitting = true (https://github.com/godotengine/godot-proposals/issues/7322)

4X3L82 commented 2 months ago

Perhaps this is related #76859 (comment)

❗ UPDATE: try using restart() instead of emitting = true (godotengine/godot-proposals#7322)

But that comment is about how to start a particle emitter, while this issue (and #93546) is about finishing it? Not to mention on my issue #93546 I do use restart() and I still don't get a finished() signal.

patwork commented 2 months ago

This is script from the MRP in this issue (sorry, I didn't look at yours):

extends GPUParticles2D

func _ready() -> void:
    one_shot = true
    emitting = true
    finished.connect(finish)

func finish() -> void:
    print("GPU Particles Destroyed!")
    queue_free()

After adding restart() in _ready() function signal will be emitted.

IMHO he problem lies in the fact that the one_shot value is changed when the emitter is already added to the scene tree and has an active emitting state.

https://github.com/godotengine/godot/blob/b97110cd307e4d78e20bfafe5de6c082194b2cd6/scene/2d/gpu_particles_2d.cpp#L43-L68

If signal_canceled is set, signal will not be emitted.