Skip to content

Commit 419e5c4

Browse files
committed
Fix particle not re-randomizing every emission
1 parent f42e612 commit 419e5c4

File tree

6 files changed

+39
-11
lines changed

6 files changed

+39
-11
lines changed

scene/2d/cpu_particles_2d.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,22 @@ void CPUParticles2D::set_emitting(bool p_emitting) {
4545
return;
4646
}
4747

48+
if (p_emitting && !use_fixed_seed) {
49+
set_seed(Math::rand());
50+
}
51+
4852
emitting = p_emitting;
4953
if (emitting) {
50-
active = true;
51-
set_process_internal(true);
54+
_set_emitting();
55+
}
56+
}
57+
58+
void CPUParticles2D::_set_emitting() {
59+
active = true;
60+
set_process_internal(true);
61+
// first update before rendering to avoid one frame delay after emitting starts
62+
if (time == 0) {
63+
_update_internal();
5264
}
5365
}
5466

@@ -310,7 +322,8 @@ void CPUParticles2D::restart(bool p_keep_seed) {
310322
seed = Math::rand();
311323
}
312324

313-
set_emitting(true);
325+
emitting = true;
326+
_set_emitting();
314327
}
315328

316329
void CPUParticles2D::set_direction(Vector2 p_direction) {

scene/2d/cpu_particles_2d.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ class CPUParticles2D : public Node2D {
186186
void _update_internal();
187187
void _particles_process(double p_delta);
188188
void _update_particle_data_buffer();
189+
void _set_emitting();
189190

190191
Mutex update_mutex;
191192

scene/2d/gpu_particles_2d.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
void GPUParticles2D::set_emitting(bool p_emitting) {
4242
// Do not return even if `p_emitting == emitting` because `emitting` is just an approximation.
4343

44+
if (p_emitting && p_emitting != emitting && !use_fixed_seed) {
45+
set_seed(Math::rand());
46+
}
4447
if (p_emitting && one_shot) {
4548
if (!active && !emitting) {
4649
// Last cycle ended.

scene/3d/cpu_particles_3d.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,22 @@ void CPUParticles3D::set_emitting(bool p_emitting) {
4848
return;
4949
}
5050

51+
if (p_emitting && !use_fixed_seed) {
52+
set_seed(Math::rand());
53+
}
54+
5155
emitting = p_emitting;
5256
if (emitting) {
53-
active = true;
54-
set_process_internal(true);
57+
_set_emitting();
58+
}
59+
}
5560

56-
// first update before rendering to avoid one frame delay after emitting starts
57-
if (time == 0) {
58-
_update_internal();
59-
}
61+
void CPUParticles3D::_set_emitting() {
62+
active = true;
63+
set_process_internal(true);
64+
// first update before rendering to avoid one frame delay after emitting starts
65+
if (time == 0) {
66+
_update_internal();
6067
}
6168
}
6269

@@ -251,7 +258,8 @@ void CPUParticles3D::restart(bool p_keep_seed) {
251258
seed = Math::rand();
252259
}
253260

254-
set_emitting(true);
261+
emitting = true;
262+
_set_emitting();
255263
}
256264

257265
void CPUParticles3D::set_direction(Vector3 p_direction) {

scene/3d/cpu_particles_3d.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ class CPUParticles3D : public GeometryInstance3D {
197197
void _update_internal();
198198
void _particles_process(double p_delta);
199199
void _update_particle_data_buffer();
200+
void _set_emitting();
200201

201202
Mutex update_mutex;
202203

scene/3d/gpu_particles_3d.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ AABB GPUParticles3D::get_aabb() const {
4242

4343
void GPUParticles3D::set_emitting(bool p_emitting) {
4444
// Do not return even if `p_emitting == emitting` because `emitting` is just an approximation.
45-
45+
if (p_emitting && p_emitting != emitting && !use_fixed_seed) {
46+
set_seed(Math::rand());
47+
}
4648
if (p_emitting && one_shot) {
4749
if (!active && !emitting) {
4850
// Last cycle ended.

0 commit comments

Comments
 (0)