From 2f3f6f69d91b78a9e964c48e9b95d4c85e2c8590 Mon Sep 17 00:00:00 2001 From: Qbieshay Date: Tue, 4 Feb 2025 11:51:17 +0100 Subject: [PATCH] Fix seed not randomizing for particles. Fix seed being stored when fixed seed is off --- scene/2d/cpu_particles_2d.cpp | 5 ++++- scene/2d/gpu_particles_2d.cpp | 6 ++++-- scene/3d/cpu_particles_3d.cpp | 5 ++++- scene/3d/gpu_particles_3d.cpp | 6 ++++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp index aa449beb1b9..76cb24867a9 100644 --- a/scene/2d/cpu_particles_2d.cpp +++ b/scene/2d/cpu_particles_2d.cpp @@ -597,7 +597,7 @@ void CPUParticles2D::_validate_property(PropertyInfo &p_property) const { } if (p_property.name == "seed" && !use_fixed_seed) { - p_property.usage = PROPERTY_USAGE_NO_EDITOR; + p_property.usage = PROPERTY_USAGE_NONE; } } @@ -1392,6 +1392,8 @@ void CPUParticles2D::_bind_methods() { BIND_ENUM_CONSTANT(DRAW_ORDER_INDEX); BIND_ENUM_CONSTANT(DRAW_ORDER_LIFETIME); + ADD_PROPERTY_DEFAULT("seed", 0); + //////////////////////////////// ClassDB::bind_method(D_METHOD("set_direction", "direction"), &CPUParticles2D::set_direction); @@ -1561,6 +1563,7 @@ CPUParticles2D::CPUParticles2D() { set_emitting(true); set_amount(8); set_use_local_coordinates(false); + set_seed(Math::rand()); rng.instantiate(); diff --git a/scene/2d/gpu_particles_2d.cpp b/scene/2d/gpu_particles_2d.cpp index 23e90582809..81c9aa82dd4 100644 --- a/scene/2d/gpu_particles_2d.cpp +++ b/scene/2d/gpu_particles_2d.cpp @@ -408,7 +408,7 @@ Ref GPUParticles2D::get_texture() const { void GPUParticles2D::_validate_property(PropertyInfo &p_property) const { if (p_property.name == "seed" && !use_fixed_seed) { - p_property.usage = PROPERTY_USAGE_NO_EDITOR; + p_property.usage = PROPERTY_USAGE_NONE; } if (p_property.name == "emitting") { p_property.hint = one_shot ? PROPERTY_HINT_ONESHOT : PROPERTY_HINT_NONE; @@ -899,6 +899,8 @@ void GPUParticles2D::_bind_methods() { BIND_ENUM_CONSTANT(EMIT_FLAG_VELOCITY); BIND_ENUM_CONSTANT(EMIT_FLAG_COLOR); BIND_ENUM_CONSTANT(EMIT_FLAG_CUSTOM); + + ADD_PROPERTY_DEFAULT("seed", 0); } GPUParticles2D::GPUParticles2D() { @@ -912,8 +914,8 @@ GPUParticles2D::GPUParticles2D() { one_shot = false; // Needed so that set_emitting doesn't access uninitialized values set_emitting(true); set_one_shot(false); + set_seed(Math::rand()); set_use_fixed_seed(false); - set_seed(0); set_amount(8); set_amount_ratio(1.0); set_lifetime(1); diff --git a/scene/3d/cpu_particles_3d.cpp b/scene/3d/cpu_particles_3d.cpp index f150e07bcaa..0f4c887652e 100644 --- a/scene/3d/cpu_particles_3d.cpp +++ b/scene/3d/cpu_particles_3d.cpp @@ -612,7 +612,7 @@ void CPUParticles3D::_validate_property(PropertyInfo &p_property) const { } if (p_property.name == "seed" && !use_fixed_seed) { - p_property.usage = PROPERTY_USAGE_NO_EDITOR; + p_property.usage = PROPERTY_USAGE_NONE; } } @@ -1564,6 +1564,8 @@ void CPUParticles3D::_bind_methods() { BIND_ENUM_CONSTANT(DRAW_ORDER_LIFETIME); BIND_ENUM_CONSTANT(DRAW_ORDER_VIEW_DEPTH); + ADD_PROPERTY_DEFAULT("seed", 0); + //////////////////////////////// ClassDB::bind_method(D_METHOD("set_direction", "direction"), &CPUParticles3D::set_direction); @@ -1764,6 +1766,7 @@ CPUParticles3D::CPUParticles3D() { set_emitting(true); set_amount(8); + set_seed(Math::rand()); rng.instantiate(); diff --git a/scene/3d/gpu_particles_3d.cpp b/scene/3d/gpu_particles_3d.cpp index db2d2f41902..2d9435ce4a9 100644 --- a/scene/3d/gpu_particles_3d.cpp +++ b/scene/3d/gpu_particles_3d.cpp @@ -464,7 +464,7 @@ void GPUParticles3D::_validate_property(PropertyInfo &p_property) const { } } if (p_property.name == "seed" && !use_fixed_seed) { - p_property.usage = PROPERTY_USAGE_NO_EDITOR; + p_property.usage = PROPERTY_USAGE_NONE; } } @@ -868,6 +868,8 @@ void GPUParticles3D::_bind_methods() { BIND_ENUM_CONSTANT(TRANSFORM_ALIGN_Z_BILLBOARD); BIND_ENUM_CONSTANT(TRANSFORM_ALIGN_Y_TO_VELOCITY); BIND_ENUM_CONSTANT(TRANSFORM_ALIGN_Z_BILLBOARD_Y_TO_VELOCITY); + + ADD_PROPERTY_DEFAULT("seed", 0); } GPUParticles3D::GPUParticles3D() { @@ -877,6 +879,7 @@ GPUParticles3D::GPUParticles3D() { one_shot = false; // Needed so that set_emitting doesn't access uninitialized values set_emitting(true); set_one_shot(false); + set_seed(Math::rand()); set_amount_ratio(1.0); set_amount(8); set_lifetime(1); @@ -895,7 +898,6 @@ GPUParticles3D::GPUParticles3D() { set_collision_base_size(collision_base_size); set_transform_align(TRANSFORM_ALIGN_DISABLED); set_use_fixed_seed(false); - set_seed(0); } GPUParticles3D::~GPUParticles3D() {