fix: Prevent infinite compilation loop in Unity 6 when using wait_for_ready (#559)
* fix: Prevent infinite compilation loop in Unity 6 when using wait_for_ready Skip WaitForUnityReadyAsync when compileRequested is true. The EditorApplication.update polling doesn't survive domain reloads properly in Unity 6, causing infinite compilation loops. When compilation is requested, return immediately and let the client poll editor_state resource instead. Fixes #557 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use actuallyWaited for hint message consistency Address code review feedback: when compile was requested and we skip WaitForUnityReadyAsync, the hint should correctly indicate that the client needs to poll editor_state, not claim the editor is ready. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: Gate Unity 6 fix with version check and rename variable Address code review feedback: - Use UNITY_6000_0_OR_NEWER preprocessor directive to only apply the compilation wait bypass on Unity 6+, preserving original behavior for earlier versions - Rename actuallyWaited to shouldWaitForReady for clarity, as it represents the decision to wait rather than a post-hoc result Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>main
parent
b6fa293cd3
commit
87d0f1d422
|
|
@ -90,7 +90,17 @@ namespace MCPForUnity.Editor.Tools
|
||||||
return new ErrorResponse($"refresh_failed: {ex.Message}");
|
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
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -122,7 +132,7 @@ namespace MCPForUnity.Editor.Tools
|
||||||
refresh_triggered = refreshTriggered,
|
refresh_triggered = refreshTriggered,
|
||||||
compile_requested = compileRequested,
|
compile_requested = compileRequested,
|
||||||
resulting_state = resultingState,
|
resulting_state = resultingState,
|
||||||
hint = waitForReady
|
hint = shouldWaitForReady
|
||||||
? "Unity refresh completed; editor should be ready."
|
? "Unity refresh completed; editor should be ready."
|
||||||
: "If Unity enters compilation/domain reload, poll editor_state until ready_for_tools is true."
|
: "If Unity enters compilation/domain reload, poll editor_state until ready_for_tools is true."
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue