-
Notifications
You must be signed in to change notification settings - Fork 693
Description
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
- Open a Unity project with MCP-for-Unity installed
- Make changes to the current scene (scene becomes dirty)
- Call run_tests with mode: "EditMode" via MCP
- Observe: Unity shows "Save Scene" modal dialog
- 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 PlayModeThis 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.