From 530665197f04f08090e2dda92a50548fb5aca374 Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Sat, 9 Nov 2019 09:51:17 +0100 Subject: [PATCH] Fixed Particles restart after visibility has been set to off and on again Make sure particles are processed during the same frame when visibility is set to on, in case they are still active from before and need to be restarted. Fixed #33476 --- scene/3d/particles.cpp | 7 +++++++ servers/visual/visual_server_raster.h | 2 ++ servers/visual/visual_server_wrap_mt.h | 2 ++ servers/visual_server.cpp | 2 ++ servers/visual_server.h | 2 ++ 5 files changed, 15 insertions(+) diff --git a/scene/3d/particles.cpp b/scene/3d/particles.cpp index 241eb7d1cad..06b5613eb86 100644 --- a/scene/3d/particles.cpp +++ b/scene/3d/particles.cpp @@ -331,6 +331,13 @@ void Particles::_notification(int p_what) { set_process_internal(false); } } + + if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { + // make sure particles are updated before rendering occurs if they were active before + if (is_visible_in_tree() && !VS::get_singleton()->particles_is_inactive(particles)) { + VS::get_singleton()->particles_request_process(particles); + } + } } void Particles::_bind_methods() { diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 0df228457e2..06096781fe8 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -409,6 +409,8 @@ public: BIND2(particles_set_process_material, RID, RID) BIND2(particles_set_fixed_fps, RID, int) BIND2(particles_set_fractional_delta, RID, bool) + BIND1R(bool, particles_is_inactive, RID) + BIND1(particles_request_process, RID) BIND1(particles_restart, RID) BIND2(particles_set_draw_order, RID, VS::ParticlesDrawOrder) diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index 273cf728c1f..59df51ff19a 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -343,6 +343,8 @@ public: FUNC2(particles_set_process_material, RID, RID) FUNC2(particles_set_fixed_fps, RID, int) FUNC2(particles_set_fractional_delta, RID, bool) + FUNC1R(bool, particles_is_inactive, RID) + FUNC1(particles_request_process, RID) FUNC1(particles_restart, RID) FUNC2(particles_set_draw_order, RID, VS::ParticlesDrawOrder) diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index 4bab9b76bac..b095f242123 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -1844,6 +1844,8 @@ void VisualServer::_bind_methods() { ClassDB::bind_method(D_METHOD("particles_set_process_material", "particles", "material"), &VisualServer::particles_set_process_material); ClassDB::bind_method(D_METHOD("particles_set_fixed_fps", "particles", "fps"), &VisualServer::particles_set_fixed_fps); ClassDB::bind_method(D_METHOD("particles_set_fractional_delta", "particles", "enable"), &VisualServer::particles_set_fractional_delta); + ClassDB::bind_method(D_METHOD("particles_is_inactive", "particles"), &VisualServer::particles_is_inactive); + ClassDB::bind_method(D_METHOD("particles_request_process", "particles"), &VisualServer::particles_request_process); ClassDB::bind_method(D_METHOD("particles_restart", "particles"), &VisualServer::particles_restart); ClassDB::bind_method(D_METHOD("particles_set_draw_order", "particles", "order"), &VisualServer::particles_set_draw_order); ClassDB::bind_method(D_METHOD("particles_set_draw_passes", "particles", "count"), &VisualServer::particles_set_draw_passes); diff --git a/servers/visual_server.h b/servers/visual_server.h index 5e6c4d9b1e1..1c1b04f1989 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -560,6 +560,8 @@ public: virtual void particles_set_process_material(RID p_particles, RID p_material) = 0; virtual void particles_set_fixed_fps(RID p_particles, int p_fps) = 0; virtual void particles_set_fractional_delta(RID p_particles, bool p_enable) = 0; + virtual bool particles_is_inactive(RID p_particles) = 0; + virtual void particles_request_process(RID p_particles) = 0; virtual void particles_restart(RID p_particles) = 0; enum ParticlesDrawOrder {