Skip to content

EditMode tests blocked by "Save Scene" dialog when scene is dirty #525

@sjennings

Description

@sjennings

Summary

When running EditMode tests via MCP with a dirty scene, Unity's "Save Scene" modal dialog blocks the editor event loop, causing MCP to timeout without receiving a response.

Root Cause

In TestRunnerService.RunTestsAsync(), the SaveDirtyScenesIfNeeded() method is only called for PlayMode tests:

// Current code (line 109-112)
if (mode == TestMode.PlayMode)
{
    SaveDirtyScenesIfNeeded();
}

This means EditMode tests don't auto-save dirty scenes, and Unity's test framework triggers a modal save dialog that blocks the entire editor.

Steps to Reproduce

  1. Open a Unity project with MCP-for-Unity installed
  2. Make changes to the current scene (scene becomes dirty)
  3. Call run_tests with mode: "EditMode" via MCP
  4. Observe: Unity shows "Save Scene" modal dialog
  5. Result: MCP times out waiting for response

Expected Behavior

EditMode tests should auto-save dirty scenes before running, just like PlayMode tests do.

Proposed Fix

Move SaveDirtyScenesIfNeeded() outside the PlayMode conditional so it runs for all test modes:

// Before _testRunnerApi.Execute(settings):
SaveDirtyScenesIfNeeded();  // Save for ALL test modes, not just PlayMode

This is a one-line change in TestRunnerService.cs.

Environment

  • Unity MCP version: 8.7.1
  • Unity version: 6.3 LTS
  • MCP Client: Claude Code

Workaround

Manually save all scenes before running tests, or create a [InitializeOnLoad] script that registers a ICallbacks handler to auto-save on RunStarted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions