Skip to content

EditorApplication.isCompiling False Positive in Play Mode #549

@hui1993

Description

@hui1993

Bug Report: EditorApplication.isCompiling False Positive in Play Mode

Summary

EditorApplication.isCompiling returns true even when Unity is not actually compiling, causing MCP tools to incorrectly return "error": "busy", "reason": "compiling" in Play mode.

Environment

  • Unity Version: 2022.3.x
  • MCP for Unity Version: Latest (git)
  • OS: macOS

Steps to Reproduce

  1. Enter Play mode in Unity Editor
  2. Use MCP client (Cursor) to call tools like find_gameobjects or manage_scene
  3. Observe intermittent "error": "busy", "reason": "compiling" errors even though Unity is not compiling

Root Cause Analysis

Through debugging, we found that EditorApplication.isCompiling can return true in Play mode even when CompilationPipeline.isCompiling (via reflection) returns false.

Debug Evidence

// Unity reports compiling but actually not compiling:
{
  "editorAppIsCompiling": true,      // ← False positive!
  "pipelineIsCompiling": false,      // ← Actually not compiling
  "possibleFalsePositive": true
}

Affected Code

Editor/Services/EditorStateCache.cs uses EditorApplication.isCompiling directly:

// Line 292
bool isCompiling = EditorApplication.isCompiling;

Proposed Fix

Add a helper method that double-checks with CompilationPipeline.isCompiling in Play mode:

private static bool GetActualIsCompiling()
{
    // First check EditorApplication.isCompiling
    if (!EditorApplication.isCompiling)
    {
        return false;
    }
    
    // In Play mode, EditorApplication.isCompiling can have false positives
    // Double-check with CompilationPipeline.isCompiling via reflection
    if (EditorApplication.isPlaying)
    {
        try
        {
            Type pipeline = Type.GetType("UnityEditor.Compilation.CompilationPipeline, UnityEditor");
            var prop = pipeline?.GetProperty("isCompiling", BindingFlags.Public | BindingFlags.Static);
            if (prop != null)
            {
                return (bool)prop.GetValue(null);
            }
        }
        catch { }
    }
    
    return EditorApplication.isCompiling;
}

Then replace:

bool isCompiling = EditorApplication.isCompiling;

with:

bool isCompiling = GetActualIsCompiling();

Workaround

Users can manually patch the local package until this is fixed upstream.

Additional Context

This issue appears to be related to Unity's internal state management during Play mode, where EditorApplication.isCompiling may not accurately reflect the actual compilation state.

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