Skip to content

fix(build): skip never-saved scenes instead of opening the save modal - #1356

Merged
Scriptwonder merged 1 commit into
CoplayDev:betafrom
Scriptwonder:fix/build-skip-untitled-scenes
Aug 31, 2026
Merged

fix(build): skip never-saved scenes instead of opening the save modal#1356
Scriptwonder merged 1 commit into
CoplayDev:betafrom
Scriptwonder:fix/build-skip-untitled-scenes

Conversation

@Scriptwonder

@Scriptwonder Scriptwonder commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to #1340, which landed in beta at 498acd1.

#1340 added SaveBeforeBuild() so manage_build would stop blocking on Unity's unsaved-scene dialog (#1341). The intent is right, but it calls EditorSceneManager.SaveOpenScenes() unconditionally:

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.");
}

A scene that has never been saved carries an empty path, and handing one to Unity's save API opens the modal "Save Scene" file panel — the exact block this change exists to prevent. The warning cannot help: it runs after SaveOpenScenes() returns, which is after the modal has already stalled the main thread.

Why this is reachable

An untitled scene is routine in agent-driven workflows — EditorSceneManager.NewScene via execute_code, or a plain Ctrl+N — and the next instruction is often "build it".

The repo already solved this twice

TestRunnerService.SaveDirtyScenes hit the same problem and guards it:

if (string.IsNullOrEmpty(scene.path))
{
    McpLog.Warn($"[TestRunnerService] Skipping unsaved scene '{scene.name}': save it manually before running tests.");
    continue;
}

ManageScene.cs:492 refuses the same case: "Cannot save an untitled scene without providing a 'name' and 'path'."

This change makes BuildRunner consistent with both: save dirty scenes individually, skip pathless ones with a warning that names the scene, and keep a per-scene try/catch so one failure does not abort the rest.

Testing

  • New EditMode tests in BuildSaveBeforeBuildTests.cs. The sharp assertion is that an untitled scene is left dirty and path-less after SaveBeforeBuild() — a saved scene would have neither, so this fails if the unconditional save ever comes back.
  • Unity 6000.4.11f1: 2/2 passed.
  • Unity 2021.3.45f2 (package floor): compile check passed.

SaveBeforeBuild changed from private to internal so the test assembly can call it directly; MCPForUnity.Editor already has InternalsVisibleTo("MCPForUnityTests.EditMode").

cc @TeapoyY — thanks for the original fix, this only adds the pathless guard on top of it.

Summary by CodeRabbit

  • Bug Fixes

    • Build preparation now saves each dirty open scene individually.
    • Unsaved scenes are skipped to prevent unexpected save dialogs.
    • Scene save failures are logged without interrupting the build process.
  • Tests

    • Added coverage for unsaved dirty scenes and builds with no dirty scenes.

CoplayDev#1340 added SaveBeforeBuild() so manage_build would not block on Unity's
unsaved-scene dialog, but it called EditorSceneManager.SaveOpenScenes()
unconditionally. A scene that has never been saved carries an empty path, and
handing one to Unity's save API opens the modal "Save Scene" file panel --
the exact block the change was meant to prevent. The warning it logs fires
only after SaveOpenScenes() returns, which is after the modal has already
stalled the main thread.

Saves dirty scenes individually and skips pathless ones with a warning,
mirroring the guard TestRunnerService.SaveDirtyScenes has carried since it hit
the same problem. ManageScene refuses the same case at ManageScene.cs:492.

Follow-up to CoplayDev#1340. Refs CoplayDev#1341
Copilot AI lite review requested due to automatic review settings August 31, 2026 22:13
@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 57020e65-2d07-46c0-b91a-36d1f4876bbf

📥 Commits

Reviewing files that changed from the base of the PR and between d2dcb0c and 43e3fcc.

📒 Files selected for processing (3)
  • MCPForUnity/Editor/Tools/Build/BuildRunner.cs
  • TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/BuildSaveBeforeBuildTests.cs
  • TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/BuildSaveBeforeBuildTests.cs.meta

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

SaveBeforeBuild now saves dirty, previously saved scenes individually and skips untitled scenes without opening modal dialogs. New EditMode tests cover untitled dirty scenes and clean-scene no-op behavior.

Changes

Build scene save handling

Layer / File(s) Summary
Per-scene save handling
MCPForUnity/Editor/Tools/Build/BuildRunner.cs
SaveBeforeBuild iterates through open scenes, saves eligible dirty scenes, skips pathless scenes with warnings, and logs individual save failures.
Scene save behavior tests
TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/BuildSaveBeforeBuildTests.cs, TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/BuildSaveBeforeBuildTests.cs.meta
EditMode tests verify untitled dirty scenes remain unsaved and that clean scenes require no action. The Unity asset metadata is added. Catches potential etc?

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 43e3f

Builds will no longer open a blocking save dialog for never-saved scenes; those scenes remain unsaved with a warning while eligible scenes continue to save. No actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides strong technical context, implementation details, and test results, but it does not follow the repository template. It omits the required section headings and checklist detail… Reformat the description using the repository template. Mark Bug fix and Test update, provide Unity versions and package source details or state that they are not applicable, mark the Unity EditMode and compile checks, document the document…
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preventing never-saved scenes from opening Unity's save modal.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description provides strong technical context, implementation details, and test results, but it does not follow the repository template. It omits the required section headings and checklist details for change type, compatibility/package source, testing, documentation updates, related issues, and additional notes.

Resolution

Reformat the description using the repository template. Mark Bug fix and Test update, provide Unity versions and package source details or state that they are not applicable, mark the Unity EditMode and compile checks, document the documentation-update status, add formal related-issue references such as "Fixes #1341" or "Relates to #1340", and complete Additional Notes if needed.

Full details: Docstring Coverage

Explanation

Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Unity-side BuildRunner.SaveBeforeBuild() logic used by the manage_build tool so automated builds don’t trigger Unity’s modal “Save Scene” file picker when an open dirty scene has never been saved (empty scene.path). Adds EditMode regression tests to pin the behavior.

Changes:

  • Change SaveBeforeBuild() to save dirty scenes individually and skip pathless (never-saved) scenes with a warning.
  • Expose SaveBeforeBuild() as internal for direct EditMode test coverage.
  • Add new EditMode tests asserting untitled scenes remain dirty/pathless after SaveBeforeBuild().

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

File Description
MCPForUnity/Editor/Tools/Build/BuildRunner.cs Adjusts pre-build save behavior to avoid opening modal save dialogs for never-saved scenes.
TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/BuildSaveBeforeBuildTests.cs Adds regression tests covering the new guard and non-throw behavior.
TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/BuildSaveBeforeBuildTests.cs.meta Adds Unity meta for the new test asset.
Files not reviewed (1)
  • TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/BuildSaveBeforeBuildTests.cs.meta: Generated file

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

/// a save dialog. Scenes that have never been saved carry an empty path, and handing one
/// to Unity's save API opens the modal "Save Scene" file panel — the exact block this is
/// meant to prevent — so those are skipped with a warning instead. Mirrors the guard in
/// TestRunnerService.SaveDirtyScenes.
Comment on lines +263 to +270
try
{
EditorSceneManager.SaveScene(scene);
}
catch (Exception ex)
{
McpLog.Warn($"[MCP Build] Failed to save dirty scene '{scene.name}': {ex.Message}");
}
}

[Test]
public void SaveBeforeBuild_WithNoDirtyScenes_IsANoOp()
@Scriptwonder
Scriptwonder merged commit c42fe0a into CoplayDev:beta Aug 31, 2026
5 checks passed
@Scriptwonder
Scriptwonder deleted the fix/build-skip-untitled-scenes branch August 31, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants