Agent skill
uloop-execute-dynamic-code
Execute C# code dynamically in Unity Editor. Use when you need to: (1) Wire prefab/material references and AddComponent operations, (2) Edit SerializedObject properties and reference wiring, (3) Perform scene/hierarchy edits and batch operations, (4) PlayMode automation (click buttons, raycast, invoke methods), (5) PlayMode UI controls (InputField, Slider, Toggle, Dropdown), (6) PlayMode inspection (scene info, reflection, physics state). NOT for file I/O or script authoring.
Install this agent skill to your Project
npx add-skill https://github.com/hatayama/unity-cli-loop/tree/main/Packages/src/Editor/Api/McpTools/ExecuteDynamicCode/Skill
SKILL.md
Task
Execute the following request using uloop execute-dynamic-code: $ARGUMENTS
Workflow
- Read the relevant reference file(s) from the Code Examples section below
- Construct C# code based on the reference examples
- Execute via Bash:
uloop execute-dynamic-code --code '<code>' - If execution fails, adjust code and retry
- Report the execution result
Parameters
--code '<code>'(required): Inline C# statements to execute. Use direct statements only;returnis optional, andusingdirectives may appear at the top of the snippet.- Shell quoting: bash/zsh uses single quotes, for example
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 asparameters["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.
Code Rules
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.
Code Examples by Category
For detailed code examples, refer to these files:
- Prefab operations: See references/prefab-operations.md
- Create prefabs, instantiate, add components, modify properties
- Material operations: See references/material-operations.md
- Create materials, set shaders/textures, modify properties
- Asset operations: See references/asset-operations.md
- Find/search assets, duplicate, move, rename, load
- ScriptableObject: See references/scriptableobject.md
- Create ScriptableObjects, modify with SerializedObject
- Scene operations: See references/scene-operations.md
- Create/modify GameObjects, set parents, wire references, load scenes
- Batch operations: See references/batch-operations.md
- Bulk modify objects, batch add/remove components, rename, layer/tag/material replacement
- Cleanup operations: See references/cleanup-operations.md
- Detect broken scripts, missing references, unused materials, empty GameObjects
- Undo operations: See references/undo-operations.md
- Undo-aware operations: RecordObject, AddComponent, SetParent, grouping
- Selection operations: See references/selection-operations.md
- Get/set selection, multi-select, filter by type/editability
- PlayMode automation: See references/playmode-automation.md
- Click UI buttons, raycast interaction, invoke methods, set fields, tool combination workflows
- PlayMode UI controls: See references/playmode-ui-controls.md
- InputField, Slider, Toggle, Dropdown, drag & drop simulation, list all UI controls
- PlayMode inspection: See references/playmode-inspection.md
- Scene info, game state via reflection, physics state, GameObject search, position/rotation
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
uloop-simulate-mouse-ui
Simulate mouse click, long-press, and drag on PlayMode UI elements via EventSystem screen coordinates. Use when you need to: (1) Click buttons or interactive UI elements during PlayMode testing, (2) Drag UI elements from one position to another, (3) Hold a drag at a position for inspection before releasing, (4) Long-press UI elements that respond to sustained pointer-down. For game logic that reads Input System (e.g. WasPressedThisFrame), use simulate-mouse-input instead.
uloop-execute-menu-item
Execute Unity Editor menu commands programmatically. Use when you need to: (1) Trigger menu commands like save, build, or refresh, (2) Automate editor actions via menu paths, (3) Run custom menu items defined in project scripts.
uloop-find-game-objects
Find GameObjects in the active scene by various criteria. Use when you need to: (1) Search for objects by name, regex, or path, (2) Find objects with specific components, tags, or layers, (3) Get currently selected GameObjects in Unity Editor. Returns matching GameObjects with hierarchy paths and components.
uloop-simulate-keyboard
Simulate keyboard key input in PlayMode via Input System. Use when you need to: (1) Press game control keys like WASD, Space, or Shift during PlayMode, (2) Hold keys down for continuous movement or actions, (3) Combine multiple held keys for complex input like Shift+W for sprint.
uloop-run-tests
Execute Unity Test Runner and get detailed results. Use when you need to: (1) Run EditMode or PlayMode unit tests, (2) Verify code changes pass all tests, (3) Diagnose test failures with error messages and stack traces. Auto-saves NUnit XML results on failure.
uloop-control-play-mode
Control Unity Editor play mode (play/stop/pause). Use when you need to: (1) Start play mode to test game behavior, (2) Stop play mode to return to edit mode, (3) Pause play mode for frame-by-frame inspection.
Didn't find tool you were looking for?