From 20ebe3ac85ab991d9fdf3bfe0bb361e981aaf744 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 19 Aug 2022 15:35:34 +0200 Subject: [PATCH] Fix game ticking in editor during cut-scene rendering at edit time --- Source/Editor/Windows/Assets/SceneAnimationWindow.cs | 8 +++++++- Source/Engine/Level/Level.cpp | 7 ++++--- Source/Engine/Level/Level.h | 6 +++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Source/Editor/Windows/Assets/SceneAnimationWindow.cs b/Source/Editor/Windows/Assets/SceneAnimationWindow.cs index 0f4a3a535..aef74e8bd 100644 --- a/Source/Editor/Windows/Assets/SceneAnimationWindow.cs +++ b/Source/Editor/Windows/Assets/SceneAnimationWindow.cs @@ -276,7 +276,7 @@ namespace FlaxEditor.Windows.Assets private float _warmUpTimeLeft; private float _dt; private int _animationFrame; - private bool _wasGamePaused; + private bool _wasGamePaused, _wasTickEnabled; private SceneAnimationPlayer _player; private States _state; private readonly StagingTexture[] _stagingTextures = new StagingTexture[FrameLatency + 1]; @@ -365,11 +365,16 @@ namespace FlaxEditor.Windows.Assets }; FlaxEngine.Scripting.Update += Tick; _wasGamePaused = Time.GamePaused; + _wasTickEnabled = Level.TickEnabled; Time.GamePaused = false; Time.SetFixedDeltaTime(true, _dt); Time.UpdateFPS = Time.DrawFPS = _options.FrameRate; if (!Editor.IsPlayMode) + { + // Don't simulate physics and don't tick game when rendering at edit time Time.PhysicsFPS = 0; + Level.TickEnabled = false; + } Level.SpawnActor(_player); var gameWin = editor.Windows.GameWin; var resolution = _options.GetResolution(); @@ -441,6 +446,7 @@ namespace FlaxEditor.Windows.Assets FlaxEngine.Scripting.Update -= Tick; Time.SetFixedDeltaTime(false, 0.0f); Time.GamePaused = _wasGamePaused; + Level.TickEnabled = _wasTickEnabled; if (_player) { _player.Stop(); diff --git a/Source/Engine/Level/Level.cpp b/Source/Engine/Level/Level.cpp index db7c52aab..98ad5a694 100644 --- a/Source/Engine/Level/Level.cpp +++ b/Source/Engine/Level/Level.cpp @@ -145,6 +145,7 @@ LevelService LevelServiceInstanceService; CriticalSection Level::ScenesLock; Array Level::Scenes; +bool Level::TickEnabled = true; Delegate Level::ActorSpawned; Delegate Level::ActorDeleted; Delegate Level::ActorParentChanged; @@ -245,7 +246,7 @@ void LevelService::Update() auto& scenes = Level::Scenes; // Update all actors - if (!Time::GetGamePaused()) + if (!Time::GetGamePaused() && Level::TickEnabled) { for (int32 i = 0; i < scenes.Count(); i++) { @@ -274,7 +275,7 @@ void LevelService::LateUpdate() auto& scenes = Level::Scenes; // Update all actors - if (!Time::GetGamePaused()) + if (!Time::GetGamePaused() && Level::TickEnabled) { for (int32 i = 0; i < scenes.Count(); i++) { @@ -306,7 +307,7 @@ void LevelService::FixedUpdate() auto& scenes = Level::Scenes; // Update all actors - if (!Time::GetGamePaused()) + if (!Time::GetGamePaused() && Level::TickEnabled) { for (int32 i = 0; i < scenes.Count(); i++) { diff --git a/Source/Engine/Level/Level.h b/Source/Engine/Level/Level.h index ae01cd572..5fc4c909b 100644 --- a/Source/Engine/Level/Level.h +++ b/Source/Engine/Level/Level.h @@ -43,6 +43,11 @@ public: /// API_FIELD(ReadOnly) static Array Scenes; + /// + /// True if game objects (actors and scripts) can receive a tick during engine Update/LateUpdate/FixedUpdate events. Can be used to temporarily disable gameplay logic updating. + /// + API_FIELD() static bool TickEnabled; + public: /// /// Occurs when new actor gets spawned to the game. @@ -104,7 +109,6 @@ public: /// /// Gets the scenes count. /// - /// The scenes count. API_PROPERTY() static int32 GetScenesCount() { return Scenes.Count();