Skip to content

Tools are often run without first ensuring the editor has updated the asset db and/or compiled #474

Closed

Description

@strich

Often code is changed and the LLM will request a console read back or try to run tests, but the editor hasn't first been told to refresh the asset db and recompile. It doesn't do this automatically because it doesn't have focus. All tool calls should ensure the editor has refreshed and the calls should survive a recompile.

Activity

  1. coderabbitai commented on Dec 20, 2025

    @coderabbitai
    Contributor

    📝 CodeRabbit Plan Mode

    Generate an implementation plan and prompts that you can use with your favorite coding agent.

    • Create Plan
    Examples

    🔗 Similar Issues

    Possible Duplicates

    Related Issues

    👤 Suggested Assignees

    🧪 Issue enrichment is currently in open beta.

    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord or schedule a call!

  2. dsarno commented on Dec 20, 2025

    @dsarno
    Collaborator

    Can you offer a repro case? There are only a few tools that change code (manage_script basically). And they reload domain reliably.

    If you're talking about your IDE (Claude, cursor) making changes directly, that doesn't force a reload, but Unity will reload on next focus.

  3. strich commented on Dec 20, 2025

    @strich
    Author

    I am indeed talking about using an external IDE. It's not viable to have to manually pull focus on the editor every time the AI wants to do something with it - Often the AI may be spending many minutes writing code, reading from the console and fixing bugs. Having to check back manually to pull focus then allow the read_console tool is frustrating and a time sink - That kind of tool call should happen in the background without my intervention.

    A good solution here would be to provide an option in the editor window settings of the package to run AssetDatabase.Refresh() on every tool call. This is assuming tool calls survive recompilations?

  4. dsarno commented on Dec 20, 2025

    @dsarno
    Collaborator

    Yes, that's less a limitation of the mcp than the way IDEs work, but I agree it'd be nice to give the IDE a tool to reload domain when it wants to check its work. (This is how Coplay works). You would only want to call it on code changes because otherwise you don't need a recompile / domain reload.

  5. strich commented on Dec 21, 2025

    @strich
    Author

    I disagree - it's not up to the IDE to tell unity things have changed. It's a failing of the MCP tools to ensure it's operating on the latest version of the assets. It would be silly to expect every IDE to somehow know it's working with a unity project and then also somehow know how to talk to the editor right?
    Also you do want to call this on all tools all the time - calling assetdatabase.refesh() won't domain reload or recompile if no code has changed. It is a harmless call to make all the time

  6. dsarno commented on Dec 21, 2025

    @dsarno
    Collaborator

    Can't disagree with a well stated case. Thanks for pushing back.

    Don't suppose you'd like to contribute a PR for it?

  7. strich commented on Dec 21, 2025

    @strich
    Author

    The only thing I'm concerned about is whether you've made the tool calls durable over editor recompilations? I have no idea.

  8. msanatan commented on Dec 22, 2025

    @msanatan
    Member

    Yes tools will retry if editor is compiling, then execute when editor is ready.

    See e.g.: https://github.com/CoplayDev/unity-mcp/blob/main/MCPForUnity/Editor/Services/HttpBridgeReloadHandler.cs

    And send_command_with_retry in https://github.com/CoplayDev/unity-mcp/blob/df906cb7477f9d9e4db04baa7b621284a9ba494e/Server/src/transport/legacy/unity_connection.py

    This is one of the dangers of having an asset reload tool with our current setup. When you do an asset DB refresh, Unity reloads the MCP plugin (not something we can control) and the reconnection happens. If the LLMs don't check state, it just tries again and gets stuck in a loop. This was tried before

  9. dsarno commented on Dec 22, 2025

    @dsarno
    Collaborator

    Agreed. This is too blunt a way to handle it. Most tools don't need a refresh. I'm going to try a more surgical approach.

  10. msanatan commented on Dec 22, 2025

    @msanatan
    Member

    At least in my experience, tools and resources for testing don't work when the Unity editor isn't in focus, regardless of if I changed the state of the tests or not.

    I'm not trying to discredit your problem @strich, but I think the solution is knowing how these tools work and ensuring we work with Unity in the correct way for each one.

    At least from my experience with Coplay, there's a balance for users to be pulled back in focus and have LLMs do things autonomously. You won't want it to be pulled in focus on every call.

  11. strich commented on Jan 1, 2026

    @strich
    Author

    At least in my experience, tools and resources for testing don't work when the Unity editor isn't in focus, regardless of if I changed the state of the tests or not.

    You may need to revalidate that - The editor should be fully capable of being run without any focus or even a head in some cases.

    I understand your concerns, but outside of the Coplay env they are minor compared to the alternative where most of the tool calls are broken and don't work due to the editor working on out of date assets. It's just not fit for purpose I'm afraid.

    You're completely correct though that all of this is moot as this MCP server doesn't currently survive domain reloads - That is an underlying issue that puts the breaks on everything here. You could resolve this by moving the server to an external process and implementing polling between it and the editor.

    But it sounds like there is low interest in doing that work? Maybe you don't deem it important within the Coplay env (which I'm not in), which is fair enough. But it makes this MCP server unworkable for standard envs I'm afraid.

  12. dsarno commented on Jan 1, 2026

    @dsarno
    Collaborator

    You're completely correct though that all of this is moot as this MCP server doesn't currently survive domain reloads - That is an underlying issue that puts the breaks on everything here. You could resolve this by moving the server to an external process and implementing polling between it and the editor.

    But it sounds like there is low interest in doing that work? Maybe you don't deem it important within the Coplay env (which I'm not in), which is fair enough. But it makes this MCP server unworkable for standard envs I'm afraid.

    This is not correct. The mcp is definitely resilient to domain reloads. If you see otherwise please submit a bug report.

    I do agree it would be good to have a tool that triggers compilation / reload from IDE on demand however. Then you could let the IDE do "yolo mode" and check its own changes for compile errors,etc. Currently reloads are triggers by our script editing tools (script_apply_edit etc). But letting IDE/LLM trigger it on demand seems reasonable if it wants to.

  13. dsarno commented on Jan 3, 2026

    @dsarno
    Collaborator

    @strich Ok check out 8.7.0. It's got a new refresh_unity tool and a bunch of smarter Unity "readiness" data that LLMs can poll to see if it's time to test, compile, etc. This should check your boxes. Thanks for the conversation and suggestions.

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