From f9a0ac507ceb886056ddc4a137094e8066defcc3 Mon Sep 17 00:00:00 2001 From: Yuri Sizov Date: Mon, 12 Jun 2023 18:18:51 +0200 Subject: [PATCH] Avoid error spam when (un)pausing GPUParticles out of tree (cherry picked from commit 991f4d51832b71753c30a289b3b2d4d9a019f7fc) --- scene/2d/gpu_particles_2d.cpp | 10 ++++++---- scene/3d/gpu_particles_3d.cpp | 20 +++++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/scene/2d/gpu_particles_2d.cpp b/scene/2d/gpu_particles_2d.cpp index 08c7b8e131a..9fd41ff227f 100644 --- a/scene/2d/gpu_particles_2d.cpp +++ b/scene/2d/gpu_particles_2d.cpp @@ -551,10 +551,12 @@ void GPUParticles2D::_notification(int p_what) { case NOTIFICATION_PAUSED: case NOTIFICATION_UNPAUSED: { - if (can_process()) { - RS::get_singleton()->particles_set_speed_scale(particles, speed_scale); - } else { - RS::get_singleton()->particles_set_speed_scale(particles, 0); + if (is_inside_tree()) { + if (can_process()) { + RS::get_singleton()->particles_set_speed_scale(particles, speed_scale); + } else { + RS::get_singleton()->particles_set_speed_scale(particles, 0); + } } } break; diff --git a/scene/3d/gpu_particles_3d.cpp b/scene/3d/gpu_particles_3d.cpp index b4131ff4b27..c5ec3ef453c 100644 --- a/scene/3d/gpu_particles_3d.cpp +++ b/scene/3d/gpu_particles_3d.cpp @@ -417,15 +417,6 @@ NodePath GPUParticles3D::get_sub_emitter() const { void GPUParticles3D::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_PAUSED: - case NOTIFICATION_UNPAUSED: { - if (can_process()) { - RS::get_singleton()->particles_set_speed_scale(particles, speed_scale); - } else { - RS::get_singleton()->particles_set_speed_scale(particles, 0); - } - } break; - // Use internal process when emitting and one_shot is on so that when // the shot ends the editor can properly update. case NOTIFICATION_INTERNAL_PROCESS: { @@ -450,6 +441,17 @@ void GPUParticles3D::_notification(int p_what) { RS::get_singleton()->particles_set_subemitter(particles, RID()); } break; + case NOTIFICATION_PAUSED: + case NOTIFICATION_UNPAUSED: { + if (is_inside_tree()) { + if (can_process()) { + RS::get_singleton()->particles_set_speed_scale(particles, speed_scale); + } else { + RS::get_singleton()->particles_set_speed_scale(particles, 0); + } + } + } break; + case NOTIFICATION_VISIBILITY_CHANGED: { // Make sure particles are updated before rendering occurs if they were active before. if (is_visible_in_tree() && !RS::get_singleton()->particles_is_inactive(particles)) {