From f78a70e1cd5f67f2828126832b64ceb6cb548317 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 30 Sep 2026 21:56:54 +0200 Subject: [PATCH] Fix Game Cooker wait on code compile/load end before cooking starts #4277 --- Source/Editor/Modules/UIModule.cs | 2 +- Source/Editor/States/EditingSceneState.cs | 3 +++ Source/Editor/States/EditorState.cs | 9 +++++++-- Source/Editor/States/PlayingState.cs | 3 +++ Source/Editor/Windows/GameCookerWindow.cs | 11 ++++++++++- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Source/Editor/Modules/UIModule.cs b/Source/Editor/Modules/UIModule.cs index 22f6e0233..85afca248 100644 --- a/Source/Editor/Modules/UIModule.cs +++ b/Source/Editor/Modules/UIModule.cs @@ -304,7 +304,7 @@ namespace FlaxEditor.Modules // _toolStripBuildScenes.Enabled = (canEditScene && !isPlayMode) || Editor.StateMachine.BuildingScenesState.IsActive; _toolStripBuildScenes.Visible = Editor.Options.Options.General.BuildActions?.Length != 0; - _toolStripCook.Enabled = Editor.Windows.GameCookerWin.CanBuild(Platform.PlatformType) && !GameCooker.IsRunning; + _toolStripCook.Enabled = Editor.Windows.GameCookerWin.CanBuild(Platform.PlatformType) && Editor.Windows.GameCookerWin.CanCook(); // var play = _toolStripPlay; var pause = _toolStripPause; diff --git a/Source/Editor/States/EditingSceneState.cs b/Source/Editor/States/EditingSceneState.cs index 72ba37d02..b2980312a 100644 --- a/Source/Editor/States/EditingSceneState.cs +++ b/Source/Editor/States/EditingSceneState.cs @@ -33,6 +33,9 @@ namespace FlaxEditor.States /// public override bool CanReloadScripts => true; + /// + public override bool CanCookGame => true; + /// public override string Status => AutoSaveStatus; diff --git a/Source/Editor/States/EditorState.cs b/Source/Editor/States/EditorState.cs index 8579492a2..15000d341 100644 --- a/Source/Editor/States/EditorState.cs +++ b/Source/Editor/States/EditorState.cs @@ -48,15 +48,20 @@ namespace FlaxEditor.States public virtual bool CanChangeScene => false; /// - /// Checks if can enter play mode in this state. + /// Checks if can start play mode in this state. /// public virtual bool CanEnterPlayMode => false; /// - /// Checks if can enter recompile scripts in this state. + /// Checks if can recompile scripts in this state. /// public virtual bool CanReloadScripts => false; + /// + /// Checks if can cook game in this state. + /// + public virtual bool CanCookGame => false; + /// /// Checks if static is valid for Editor UI calls and other stuff. /// diff --git a/Source/Editor/States/PlayingState.cs b/Source/Editor/States/PlayingState.cs index a81487e43..87ff72c59 100644 --- a/Source/Editor/States/PlayingState.cs +++ b/Source/Editor/States/PlayingState.cs @@ -37,6 +37,9 @@ namespace FlaxEditor.States /// public override bool CanEnterPlayMode => true; + /// + public override bool CanCookGame => true; + /// /// Occurs when play mode is starting (before scene duplicating). /// diff --git a/Source/Editor/Windows/GameCookerWindow.cs b/Source/Editor/Windows/GameCookerWindow.cs index bfbbad0ac..ad43a3ee0 100644 --- a/Source/Editor/Windows/GameCookerWindow.cs +++ b/Source/Editor/Windows/GameCookerWindow.cs @@ -927,6 +927,15 @@ namespace FlaxEditor.Windows _exitOnBuildEnd = true; } + /// + /// Returns true if can cook game now (based on editor state). + /// + /// True if can cook, otherwise false. + public bool CanCook() + { + return !GameCooker.IsRunning && Editor.StateMachine.CurrentState.CanCookGame; + } + /// /// Returns true if can build for the given platform (both supported and available). /// @@ -1290,7 +1299,7 @@ namespace FlaxEditor.Windows public override void OnUpdate() { // Building queue - if (!GameCooker.IsRunning) + if (CanCook()) { if (_buildingQueue.Count > 0) {