Skip to content

Commit 923eb44

Browse files
committed
Merge pull request godotengine#101617 from paddy-exe/processmaterial-vs-shadermaterial
Fix `emission_shape_changed` signal error when using ShaderMaterial with GPUParticles3D
2 parents 97daaca + 484d6d4 commit 923eb44

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

doc/classes/ParticleProcessMaterial.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@
418418
<signal name="emission_shape_changed">
419419
<description>
420420
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.
421+
[b]Note:[/b] This signal is only emitted inside the editor for performance reasons.
421422
</description>
422423
</signal>
423424
</signals>

scene/3d/gpu_particles_3d.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,23 @@ void GPUParticles3D::set_use_local_coordinates(bool p_enable) {
145145
}
146146

147147
void GPUParticles3D::set_process_material(const Ref<Material> &p_material) {
148+
#ifdef TOOLS_ENABLED
149+
if (process_material.is_valid()) {
150+
if (Ref<ParticleProcessMaterial>(process_material).is_valid()) {
151+
process_material->disconnect("emission_shape_changed", callable_mp((Node3D *)this, &GPUParticles3D::update_gizmos));
152+
}
153+
}
154+
#endif
155+
148156
process_material = p_material;
149157
RID material_rid;
150158
if (process_material.is_valid()) {
151159
material_rid = process_material->get_rid();
152-
process_material->connect("emission_shape_changed", callable_mp((Node3D *)this, &GPUParticles3D::update_gizmos));
160+
#ifdef TOOLS_ENABLED
161+
if (Ref<ParticleProcessMaterial>(process_material).is_valid()) {
162+
process_material->connect("emission_shape_changed", callable_mp((Node3D *)this, &GPUParticles3D::update_gizmos));
163+
}
164+
#endif
153165
}
154166
RS::get_singleton()->particles_set_process_material(particles, material_rid);
155167

@@ -554,9 +566,6 @@ void GPUParticles3D::_notification(int p_what) {
554566

555567
case NOTIFICATION_EXIT_TREE: {
556568
RS::get_singleton()->particles_set_subemitter(particles, RID());
557-
558-
Ref<ParticleProcessMaterial> material = get_process_material();
559-
ERR_FAIL_COND(material.is_null());
560569
} break;
561570

562571
case NOTIFICATION_SUSPENDED:

0 commit comments

Comments
 (0)