Skip to content

Agents sleep after script changes #814

@smuhlaci

Description

@smuhlaci

Problem

When an AI agent (e.g. in Cursor) edits a script and then needs to play the game or run other Unity operations, it must wait for Unity to finish recompiling. Today there is no dedicated way to “wait until compilation is done,” so agents tend to:

  1. Use fixed sleeps (e.g. sleep 5, sleep 3) after script changes, which is slow and brittle (sometimes compile is done in 1s, sometimes longer).
  2. Poll the editor_state resource for compilation.is_compiling in a loop, which works but is verbose and easy to get wrong.

In a real “play → read console → fix error → re-verify” workflow, this led to roughly ~12 seconds of sleep in a single run (play wait, recompile wait, play-again wait), making the loop feel slow even when the actual fix was simple.

Proposed solution

Add a wait_for_compilation capability so the agent can explicitly wait for compilation (and domain reload) to finish instead of guessing with sleeps or implementing custom polling.

Concretely:

  • manage_editor(action="wait_for_compilation")
    • Server-side only (no new Unity C# API required).
    • Uses existing editor_state / compilation state and the existing “wait for editor ready” logic (e.g. wait_for_editor_ready / wait_for_no_compile) to block until compilation is done.
    • Optional timeout (e.g. default 30s, max 120s).
    • Returns as soon as compilation is already done, or after it finishes within the timeout.

This keeps the workflow clear for the agent:

  1. manage_script(action="update", ...) — apply script change
  2. manage_editor(action="wait_for_compilation") — wait until Unity is ready
  3. manage_editor(action="play") — enter play mode
  4. read_console(...) — check for errors

No play_and_check or other new high-level action is required for this step; the main win is removing the need for long, fixed sleeps and ad-hoc polling.

References

  • Here is my chat log
Image Image

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