Skip to content

Trigger Unity's script compilation? #305

Closed

Description

@Doidel

I get the following output from my AI:

Let's test: Can you trigger Unity's script compilation?

● No, I cannot trigger Unity's script compilation through Unity MCP.

Why not:

  • Unity MCP can create/edit scripts via file operations
  • dotnet build compiles to Temp/bin/Debug/ (not usable by Unity)
  • Unity compiles to Library/ScriptAssemblies/ (only happens in Unity Editor)
  • File system operations (touch, editing files) don't auto-trigger compilation via MCP
  • No reimport_asset or force_compile action exists in Unity MCP

Current workflow:

  1. I create/edit script via Unity MCP
  2. User opens Unity Editor
  3. Unity auto-detects changes and compiles
  4. Component becomes available

What would enable auto-compilation:
Unity MCP would need to add actions like reimport_asset() or trigger_compilation() to programmatically invoke
Unity's AssetDatabase refresh.

Is that true? Or do I just have a problem locally?
Thanks!

Activity

  1. msanatan commented on Oct 6, 2025

    @msanatan
    Member

    Hey! I believe that's true, it's not a single function we expose via MCP. Why would you like it exposed? Usually Unity does it by itself after script changes are saved for e.g.

  2. Doidel commented on Oct 6, 2025

    @Doidel
    Author

    I believe Claude Code created a MonoBehaviour and wanted to attach it to a GameObject (directly in the editor). But without Unity's script compilation this results in an error, because the script is unknown to Unity.
    So currently Claude Code creates the files, then displays a ToDo list for me, e.g. "1. Run Unity's compilation, then attach the new script to GameObject xy".

  3. msanatan commented on Oct 6, 2025

    @msanatan
    Member

    I understand. I guess Unity wasn't in focus? So no domain reload happened, and the script could not have been attached. The better flow would be for CC to write all the scripts necessary, do a domain reload, check the editor state, and then when ready attach the scripts.

    I think this is something we can add, or revisit how we write files. Thanks for sharing

  4. Doidel commented on Oct 6, 2025

    @Doidel
    Author

    Yes, Unity wasn't in focus.
    Thanks! That would be great. In the meantime I'll try to teach it this exact flow, where it waits until I focus the editor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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