From a3071400c2679b52f13cc0f4fd3d949dff958b37 Mon Sep 17 00:00:00 2001 From: teapoy <605528224@qq.com> Date: Sat, 22 Aug 2026 02:39:45 +0800 Subject: [PATCH] fix(build): save assets and scenes before BuildPlayer Prevent manage_build from blocking on Unity's unsaved-scene dialog by calling AssetDatabase.SaveAssets and EditorSceneManager.SaveOpenScenes before BuildPipeline.BuildPlayer runs. Co-authored-by: Cursor --- MCPForUnity/Editor/Tools/Build/BuildRunner.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/MCPForUnity/Editor/Tools/Build/BuildRunner.cs b/MCPForUnity/Editor/Tools/Build/BuildRunner.cs index baed78da6..cb9a38df0 100644 --- a/MCPForUnity/Editor/Tools/Build/BuildRunner.cs +++ b/MCPForUnity/Editor/Tools/Build/BuildRunner.cs @@ -4,6 +4,7 @@ using UnityEditor; using UnityEditor.Build.Reporting; using UnityEditor.Build; +using UnityEditor.SceneManagement; using MCPForUnity.Editor.Helpers; namespace MCPForUnity.Editor.Tools.Build @@ -110,6 +111,7 @@ private static void RunBuildCore(BuildJob job, Func buildFunc) try { + SaveBeforeBuild(); BuildReport report = buildFunc(); job.CompletedAt = DateTime.UtcNow; @@ -230,5 +232,19 @@ private static string[] GetDefaultScenes() .Select(s => s.path) .ToArray(); } + + /// + /// Saves assets and open scenes before building so BuildPipeline does not block on a save dialog. + /// + private static void SaveBeforeBuild() + { + AssetDatabase.SaveAssets(); + if (!EditorSceneManager.SaveOpenScenes()) + { + McpLog.Warn( + "[MCP Build] Some modified scenes could not be saved (new scenes need a path). " + + "Build may still prompt to save."); + } + } } }