From 484d6d4aa179c63d29a6a2b5dfa1c631f4a9a1a6 Mon Sep 17 00:00:00 2001 From: Patrick Exner Date: Thu, 16 Jan 2025 01:18:43 +0100 Subject: [PATCH] Fix emission_shape_changed signal error when using ShaderMaterial with 3DGPUParticles --- doc/classes/ParticleProcessMaterial.xml | 1 + scene/3d/gpu_particles_3d.cpp | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/doc/classes/ParticleProcessMaterial.xml b/doc/classes/ParticleProcessMaterial.xml index 8336899e869..7118df8ed85 100644 --- a/doc/classes/ParticleProcessMaterial.xml +++ b/doc/classes/ParticleProcessMaterial.xml @@ -418,6 +418,7 @@ Emitted when this material's emission shape is changed in any way. This includes changes to [member emission_shape], [member emission_shape_scale], or [member emission_sphere_radius], and any other property that affects the emission shape's offset, size, scale, or orientation. + [b]Note:[/b] This signal is only emitted inside the editor for performance reasons. diff --git a/scene/3d/gpu_particles_3d.cpp b/scene/3d/gpu_particles_3d.cpp index 2b748e88b55..3efc9b2d5ec 100644 --- a/scene/3d/gpu_particles_3d.cpp +++ b/scene/3d/gpu_particles_3d.cpp @@ -145,11 +145,23 @@ void GPUParticles3D::set_use_local_coordinates(bool p_enable) { } void GPUParticles3D::set_process_material(const Ref &p_material) { +#ifdef TOOLS_ENABLED + if (process_material.is_valid()) { + if (Ref(process_material).is_valid()) { + process_material->disconnect("emission_shape_changed", callable_mp((Node3D *)this, &GPUParticles3D::update_gizmos)); + } + } +#endif + process_material = p_material; RID material_rid; if (process_material.is_valid()) { material_rid = process_material->get_rid(); - process_material->connect("emission_shape_changed", callable_mp((Node3D *)this, &GPUParticles3D::update_gizmos)); +#ifdef TOOLS_ENABLED + if (Ref(process_material).is_valid()) { + process_material->connect("emission_shape_changed", callable_mp((Node3D *)this, &GPUParticles3D::update_gizmos)); + } +#endif } RS::get_singleton()->particles_set_process_material(particles, material_rid); @@ -554,9 +566,6 @@ void GPUParticles3D::_notification(int p_what) { case NOTIFICATION_EXIT_TREE: { RS::get_singleton()->particles_set_subemitter(particles, RID()); - - Ref material = get_process_material(); - ERR_FAIL_COND(material.is_null()); } break; case NOTIFICATION_SUSPENDED: