From ad15c5b2fcecabec14fb7b31402d4b9ca42f2f94 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 21 Oct 2023 13:36:39 -0500 Subject: [PATCH 1/3] Fix particles effect not being able to just call play if islooped is false. --- Source/Engine/Particles/ParticleEffect.h | 2 +- Source/Engine/Particles/Particles.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Particles/ParticleEffect.h b/Source/Engine/Particles/ParticleEffect.h index 9e9792a4c..07d82d703 100644 --- a/Source/Engine/Particles/ParticleEffect.h +++ b/Source/Engine/Particles/ParticleEffect.h @@ -133,7 +133,7 @@ public: /// /// The particle system instance that plays the particles simulation in the game. /// -API_CLASS(Attributes="ActorContextMenu(\"New/Visuals/Particle Effects\"), ActorToolbox(\"Visuals\")") +API_CLASS(Attributes="ActorContextMenu(\"New/Visuals/Particle Effect\"), ActorToolbox(\"Visuals\")") class FLAXENGINE_API ParticleEffect : public Actor { DECLARE_SCENE_OBJECT(ParticleEffect); diff --git a/Source/Engine/Particles/Particles.cpp b/Source/Engine/Particles/Particles.cpp index 5850b6736..c039f4ba6 100644 --- a/Source/Engine/Particles/Particles.cpp +++ b/Source/Engine/Particles/Particles.cpp @@ -1318,6 +1318,7 @@ void ParticlesSystem::Job(int32 index) emitterInstance.Buffer = nullptr; } } + effect->Stop(); return; } } From 7d9991999d583a2c0ed89ff15bf1c1aa8046d7c2 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 21 Oct 2023 14:08:23 -0500 Subject: [PATCH 2/3] Better fix. --- Source/Engine/Particles/ParticleEffect.cpp | 4 ++++ Source/Engine/Particles/Particles.cpp | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Particles/ParticleEffect.cpp b/Source/Engine/Particles/ParticleEffect.cpp index 788a4263f..656a61991 100644 --- a/Source/Engine/Particles/ParticleEffect.cpp +++ b/Source/Engine/Particles/ParticleEffect.cpp @@ -283,6 +283,10 @@ void ParticleEffect::UpdateSimulation(bool singleFrame) void ParticleEffect::Play() { + // Reset simulation when play is called and particle system is time is complete - ex. if IsLooping is false and simulation is complete + if (!IsLooping && Instance.Time >= (float)ParticleSystem->DurationFrames / ParticleSystem->FramesPerSecond) + ResetSimulation(); + _isPlaying = true; } diff --git a/Source/Engine/Particles/Particles.cpp b/Source/Engine/Particles/Particles.cpp index c039f4ba6..15d484f8a 100644 --- a/Source/Engine/Particles/Particles.cpp +++ b/Source/Engine/Particles/Particles.cpp @@ -1318,7 +1318,8 @@ void ParticlesSystem::Job(int32 index) emitterInstance.Buffer = nullptr; } } - effect->Stop(); + // Set is playing to false because it is not playing anymore. + effect->Pause(); return; } } From 78aae0da5a18afdc8e528cfe59427b069b2cb501 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 21 Oct 2023 17:22:02 -0500 Subject: [PATCH 3/3] Better handling stopping/resetting non-looping effect. --- Source/Engine/Particles/ParticleEffect.cpp | 8 +++----- Source/Engine/Particles/ParticleEffect.h | 1 + Source/Engine/Particles/Particles.cpp | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Source/Engine/Particles/ParticleEffect.cpp b/Source/Engine/Particles/ParticleEffect.cpp index 656a61991..e461f332e 100644 --- a/Source/Engine/Particles/ParticleEffect.cpp +++ b/Source/Engine/Particles/ParticleEffect.cpp @@ -283,11 +283,8 @@ void ParticleEffect::UpdateSimulation(bool singleFrame) void ParticleEffect::Play() { - // Reset simulation when play is called and particle system is time is complete - ex. if IsLooping is false and simulation is complete - if (!IsLooping && Instance.Time >= (float)ParticleSystem->DurationFrames / ParticleSystem->FramesPerSecond) - ResetSimulation(); - _isPlaying = true; + _isStopped = false; } void ParticleEffect::Pause() @@ -297,6 +294,7 @@ void ParticleEffect::Pause() void ParticleEffect::Stop() { + _isStopped = true; _isPlaying = false; ResetSimulation(); } @@ -452,7 +450,7 @@ void ParticleEffect::Update() void ParticleEffect::UpdateExecuteInEditor() { // Auto-play in Editor - if (!Editor::IsPlayMode) + if (!Editor::IsPlayMode && !_isStopped) { _isPlaying = true; Update(); diff --git a/Source/Engine/Particles/ParticleEffect.h b/Source/Engine/Particles/ParticleEffect.h index 07d82d703..d3f0cc9d0 100644 --- a/Source/Engine/Particles/ParticleEffect.h +++ b/Source/Engine/Particles/ParticleEffect.h @@ -185,6 +185,7 @@ private: Array _parameters; // Cached for scripting API Array _parametersOverrides; // Cached parameter modifications to be applied to the parameters bool _isPlaying = false; + bool _isStopped = false; public: /// diff --git a/Source/Engine/Particles/Particles.cpp b/Source/Engine/Particles/Particles.cpp index 15d484f8a..52845a0f8 100644 --- a/Source/Engine/Particles/Particles.cpp +++ b/Source/Engine/Particles/Particles.cpp @@ -1318,8 +1318,8 @@ void ParticlesSystem::Job(int32 index) emitterInstance.Buffer = nullptr; } } - // Set is playing to false because it is not playing anymore. - effect->Pause(); + // Stop playing effect. + effect->Stop(); return; } }