diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp index 76cb24867a9..279bb8ff3d9 100644 --- a/scene/2d/cpu_particles_2d.cpp +++ b/scene/2d/cpu_particles_2d.cpp @@ -45,10 +45,22 @@ void CPUParticles2D::set_emitting(bool p_emitting) { return; } + if (p_emitting && !use_fixed_seed) { + set_seed(Math::rand()); + } + emitting = p_emitting; if (emitting) { - active = true; - set_process_internal(true); + _set_emitting(); + } +} + +void CPUParticles2D::_set_emitting() { + active = true; + set_process_internal(true); + // first update before rendering to avoid one frame delay after emitting starts + if (time == 0) { + _update_internal(); } } @@ -310,7 +322,8 @@ void CPUParticles2D::restart(bool p_keep_seed) { seed = Math::rand(); } - set_emitting(true); + emitting = true; + _set_emitting(); } void CPUParticles2D::set_direction(Vector2 p_direction) { diff --git a/scene/2d/cpu_particles_2d.h b/scene/2d/cpu_particles_2d.h index 4c0ffff417a..72fdf65a0af 100644 --- a/scene/2d/cpu_particles_2d.h +++ b/scene/2d/cpu_particles_2d.h @@ -186,6 +186,7 @@ private: void _update_internal(); void _particles_process(double p_delta); void _update_particle_data_buffer(); + void _set_emitting(); Mutex update_mutex; diff --git a/scene/2d/gpu_particles_2d.cpp b/scene/2d/gpu_particles_2d.cpp index 81c9aa82dd4..f9806c3ebf0 100644 --- a/scene/2d/gpu_particles_2d.cpp +++ b/scene/2d/gpu_particles_2d.cpp @@ -41,6 +41,9 @@ void GPUParticles2D::set_emitting(bool p_emitting) { // Do not return even if `p_emitting == emitting` because `emitting` is just an approximation. + if (p_emitting && p_emitting != emitting && !use_fixed_seed) { + set_seed(Math::rand()); + } if (p_emitting && one_shot) { if (!active && !emitting) { // Last cycle ended. diff --git a/scene/3d/cpu_particles_3d.cpp b/scene/3d/cpu_particles_3d.cpp index 0f4c887652e..8f20c754e26 100644 --- a/scene/3d/cpu_particles_3d.cpp +++ b/scene/3d/cpu_particles_3d.cpp @@ -48,15 +48,22 @@ void CPUParticles3D::set_emitting(bool p_emitting) { return; } + if (p_emitting && !use_fixed_seed) { + set_seed(Math::rand()); + } + emitting = p_emitting; if (emitting) { - active = true; - set_process_internal(true); + _set_emitting(); + } +} - // first update before rendering to avoid one frame delay after emitting starts - if (time == 0) { - _update_internal(); - } +void CPUParticles3D::_set_emitting() { + active = true; + set_process_internal(true); + // first update before rendering to avoid one frame delay after emitting starts + if (time == 0) { + _update_internal(); } } @@ -251,7 +258,8 @@ void CPUParticles3D::restart(bool p_keep_seed) { seed = Math::rand(); } - set_emitting(true); + emitting = true; + _set_emitting(); } void CPUParticles3D::set_direction(Vector3 p_direction) { diff --git a/scene/3d/cpu_particles_3d.h b/scene/3d/cpu_particles_3d.h index 64699e8b04b..eba98100bad 100644 --- a/scene/3d/cpu_particles_3d.h +++ b/scene/3d/cpu_particles_3d.h @@ -197,6 +197,7 @@ private: void _update_internal(); void _particles_process(double p_delta); void _update_particle_data_buffer(); + void _set_emitting(); Mutex update_mutex; diff --git a/scene/3d/gpu_particles_3d.cpp b/scene/3d/gpu_particles_3d.cpp index 2d9435ce4a9..4ae2ca3f8f7 100644 --- a/scene/3d/gpu_particles_3d.cpp +++ b/scene/3d/gpu_particles_3d.cpp @@ -42,7 +42,9 @@ AABB GPUParticles3D::get_aabb() const { void GPUParticles3D::set_emitting(bool p_emitting) { // Do not return even if `p_emitting == emitting` because `emitting` is just an approximation. - + if (p_emitting && p_emitting != emitting && !use_fixed_seed) { + set_seed(Math::rand()); + } if (p_emitting && one_shot) { if (!active && !emitting) { // Last cycle ended.