-
Notifications
You must be signed in to change notification settings - Fork 585
Added AssetDatabase.Refresh() to all command tool calls #475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| using MCPForUnity.Editor.Resources; | ||
| using Newtonsoft.Json; | ||
| using Newtonsoft.Json.Linq; | ||
| using UnityEditor; | ||
|
|
||
| namespace MCPForUnity.Editor.Tools | ||
| { | ||
|
|
@@ -232,6 +233,7 @@ public static Func<JObject, object> GetHandler(string commandName) | |
| /// <returns>The result for synchronous commands, or null for async commands (TCS will be completed later)</returns> | ||
| public static object ExecuteCommand(string commandName, JObject @params, TaskCompletionSource<string> tcs) | ||
| { | ||
| AssetDatabase.Refresh(); | ||
| var handlerInfo = GetHandlerInfo(commandName); | ||
|
|
||
| if (handlerInfo.IsAsync) | ||
|
|
@@ -256,6 +258,7 @@ public static object ExecuteCommand(string commandName, JObject @params, TaskCom | |
| /// <param name="params">Parameters to pass to the command (optional).</param> | ||
| public static Task<object> InvokeCommandAsync(string commandName, JObject @params) | ||
| { | ||
| AssetDatabase.Refresh(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same performance concern applies, with additional batch execution impact. This method is explicitly documented (line 255) as being "used internally for features like batch execution," making the unconditional
The same alternatives suggested for 🤖 Prompt for AI Agents |
||
| var handlerInfo = GetHandlerInfo(commandName); | ||
| var payload = @params ?? new JObject(); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
find MCPForUnity -name "CommandRegistry.cs" -type fRepository: CoplayDev/unity-mcp
Length of output: 106
🏁 Script executed:
git ls-files "MCPForUnity/Editor/Tools/CommandRegistry.cs"Repository: CoplayDev/unity-mcp
Length of output: 106
🏁 Script executed:
fd -t f "CommandRegistry.cs" --max-results 5Repository: CoplayDev/unity-mcp
Length of output: 155
🏁 Script executed:
cat -n "MCPForUnity/Editor/Tools/CommandRegistry.cs"Repository: CoplayDev/unity-mcp
Length of output: 19060
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 1061
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 314
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 274
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 655
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 6648
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 4882
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 842
Reconsider unconditional AssetDatabase.Refresh() for performance reasons.
AssetDatabase.Refresh()is a blocking, expensive operation that scans the entire project filesystem and triggers asset garbage collection. Calling it before every command execution creates significant performance issues, especially for:ExecuteMenuItem,ReadConsole)Consider these alternatives:
RequiresAssetRefresh = true) so only commands that modify assets trigger a refreshAssetDatabase.Refresh(path)when known🤖 Prompt for AI Agents