一键导入
uloop-execute-dynamic-code
// Execute C# with Unity APIs when existing uloop tools cannot inspect or edit enough. Use for scene, prefab, SerializedObject, AssetDatabase refresh/.meta generation, menu, or PlayMode automation.
// Execute C# with Unity APIs when existing uloop tools cannot inspect or edit enough. Use for scene, prefab, SerializedObject, AssetDatabase refresh/.meta generation, menu, or PlayMode automation.
| name | uloop-execute-dynamic-code |
| description | Execute C# with Unity APIs when existing uloop tools cannot inspect or edit enough. Use for scene, prefab, SerializedObject, AssetDatabase refresh/.meta generation, menu, or PlayMode automation. |
| context | fork |
Execute the following request using uloop execute-dynamic-code: $ARGUMENTS
For basic selected GameObject discovery or property inspection, use find-game-objects --search-mode Selected before this tool. Use this tool after the built-in inspection tools are not enough or when you need to modify Unity state.
uloop execute-dynamic-code --code '<code>'--code '<code>' (required): Inline C# statements to execute. Use direct statements only; return is optional, and using directives may appear at the top of the snippet.uloop execute-dynamic-code --code 'using UnityEngine; return Mathf.PI;'. PowerShell doubles inner quotes ('Debug.Log(""Hello!"");').--parameters {} (advanced, optional): Pass an object when reusing a snippet with varying data or when keeping values outside the code. Values are exposed as parameters["param0"], parameters["param1"], and so on. Omit this flag for most snippets, and pass an object instead of a JSON string.--compile-only true (optional): Compile the snippet without executing it. Use this when you want Roslyn diagnostics before running new code.Write direct statements only — no class/namespace/method wrappers. Return is optional.
using UnityEngine;
float x = Mathf.PI;
return x;
Forbidden — these will be rejected at compile time: System.IO.*, AssetDatabase.CreateFolder, creating/editing .cs/.asmdef files. Use terminal commands for file operations instead.
Returns JSON:
Success: boolean — overall execution successResult: string — value of the snippet's return statement (empty when omitted)Logs: string[] — Debug.Log / Debug.LogWarning / Debug.LogError messages emitted during the runCompilationErrors: object[] — Roslyn diagnostics with Message, Line, Column, ErrorCode, optional Hint and SuggestionsErrorMessage: string — top-level failure summary (empty on success)Error: string — alias of ErrorMessageSecurityLevel: string — dynamic-code security level active for the requestUpdatedCode: string|null — the wrapped form actually compiled (handy when debugging using-statement reordering)DiagnosticsSummary: string|null — compact summary when diagnostics are availableDiagnostics: object[] — structured diagnostics; same shape as CompilationErrors, usually populated together with itOn Success: false, inspect CompilationErrors first. If empty, read ErrorMessage (and Logs for extra context) — the failure may be a runtime exception, security violation, cancellation, or an "execution in progress" rejection, all of which return empty CompilationErrors. Both EditMode and PlayMode are supported targets — the snippet runs in whichever mode the Editor is currently in.
For detailed code examples, refer to these files:
Use when Unity Editor is not running or needs a clean restart.
Clear Unity Console entries. Use before compile, tests, or debugging when stale logs would hide the current result.
Compile the Unity project and report errors/warnings. Use after C# edits or when a full Domain Reload compile is needed.
Control Unity Editor Play Mode. Use to start, stop, or pause Play Mode for runtime behavior checks and frame inspection.
Find or inspect Unity GameObjects, especially objects the user currently selected in the Hierarchy. Use for details, components, tags, layers, or name/path searches.
Get the Unity scene hierarchy as a structured tree. Use for parent-child structure, descendants, roots, or subtrees under objects the user currently selected.