diff --git a/MCPForUnity/Editor/Tools/RefreshUnity.cs b/MCPForUnity/Editor/Tools/RefreshUnity.cs index 577ae7d..2059d84 100644 --- a/MCPForUnity/Editor/Tools/RefreshUnity.cs +++ b/MCPForUnity/Editor/Tools/RefreshUnity.cs @@ -90,7 +90,17 @@ namespace MCPForUnity.Editor.Tools return new ErrorResponse($"refresh_failed: {ex.Message}"); } - if (waitForReady) + // Unity 6+ fix: Skip wait_for_ready when compile was requested. + // The EditorApplication.update polling in WaitForUnityReadyAsync doesn't survive + // domain reloads properly in Unity 6+, causing infinite compilation loops. + // When compilation is requested, return immediately and let client poll editor_state. + // Earlier Unity versions retain the original behavior. +#if UNITY_6000_0_OR_NEWER + bool shouldWaitForReady = waitForReady && !compileRequested; +#else + bool shouldWaitForReady = waitForReady; +#endif + if (shouldWaitForReady) { try { @@ -122,7 +132,7 @@ namespace MCPForUnity.Editor.Tools refresh_triggered = refreshTriggered, compile_requested = compileRequested, resulting_state = resultingState, - hint = waitForReady + hint = shouldWaitForReady ? "Unity refresh completed; editor should be ready." : "If Unity enters compilation/domain reload, poll editor_state until ready_for_tools is true." });