hatayama

uloop-execute-dynamic-code

@hatayama/uloop-execute-dynamic-code
hatayama
113
10 forks
Updated 1/18/2026
View on GitHub

Execute C# code dynamically in Unity Editor via uloop CLI. Use for editor automation: (1) Prefab/material wiring and AddComponent operations, (2) Reference wiring with SerializedObject, (3) Scene/hierarchy edits and batch operations. NOT for file I/O or script authoring.

Installation

$skills install @hatayama/uloop-execute-dynamic-code
Claude Code
Cursor
Copilot
Codex
Antigravity

Details

Path.claude/skills/uloop-execute-dynamic-code/SKILL.md
Branchmain
Scoped Name@hatayama/uloop-execute-dynamic-code

Usage

After installing, this skill will be available to your AI coding assistant.

Verify installation:

skills list

Skill Instructions


name: uloop-execute-dynamic-code description: Execute C# code dynamically in Unity Editor via uloop CLI. Use for editor automation: (1) Prefab/material wiring and AddComponent operations, (2) Reference wiring with SerializedObject, (3) Scene/hierarchy edits and batch operations. NOT for file I/O or script authoring.

uloop execute-dynamic-code

Execute C# code dynamically in Unity Editor.

Usage

uloop execute-dynamic-code --code '<c# code>'

Parameters

ParameterTypeDescription
--codestringC# code to execute (direct statements, no class wrapper)
--compile-onlybooleanCompile without execution
--auto-qualify-unity-types-oncebooleanAuto-qualify Unity types
--allow-parallelbooleanEnable parallel execution (⚠️ use with caution)
--fire-and-forgetbooleanFire-and-forget mode (return after compile, execute in background)

Code Format

Write direct statements only (no classes/namespaces/methods). Return is optional.

// Using directives at top are hoisted
using UnityEngine;
var x = Mathf.PI;
return x;

String Literals (Shell-specific)

ShellMethod
bash/zsh/MINGW64/Git Bash'Debug.Log("Hello!");'
PowerShell'Debug.Log(""Hello!"");'

Allowed Operations

  • Prefab/material wiring (PrefabUtility)
  • AddComponent + reference wiring (SerializedObject)
  • Scene/hierarchy edits
  • Inspector modifications

Forbidden Operations

  • System.IO.* (File/Directory/Path)
  • AssetDatabase.CreateFolder / file writes
  • Create/edit .cs/.asmdef files

Examples

bash / zsh / MINGW64 / Git Bash

uloop execute-dynamic-code --code 'return Selection.activeGameObject?.name;'
uloop execute-dynamic-code --code 'new GameObject("MyObject");'
uloop execute-dynamic-code --code 'UnityEngine.Debug.Log("Hello from CLI!");'

PowerShell

uloop execute-dynamic-code --code 'return Selection.activeGameObject?.name;'
uloop execute-dynamic-code --code 'new GameObject(""MyObject"");'
uloop execute-dynamic-code --code 'UnityEngine.Debug.Log(""Hello from CLI!"");'

Output

Returns JSON with execution result or compile errors.

Notes

For file/directory operations, use terminal commands instead.

Code Examples by Category

For detailed code examples, refer to these files:

Parallel Execution Mode

--allow-parallel enables concurrent execution of multiple requests.

uloop execute-dynamic-code --code 'new GameObject("Object1");' --allow-parallel

⚠️ Risks

  • Race conditions: Simultaneous modifications to the same GameObject may cause unpredictable behavior
  • Undo complexity: Each parallel execution creates its own Undo group
  • Unity API thread safety: Some Unity APIs are not thread-safe

When to Use

  • Independent operations (e.g., creating objects in different locations)
  • Non-overlapping asset modifications
  • Read-only operations (queries, searches)

When NOT to Use

  • Modifying the same GameObject or component from multiple executions
  • Operations with sequential dependencies
  • Operations that require consistent Editor state

Fire-and-Forget Mode

--fire-and-forget returns immediately after successful compilation. Execution continues in Unity background.

# Start a long-running monitoring task - CLI returns immediately
uloop execute-dynamic-code --fire-and-forget --allow-parallel --code '
while (GameObject.Find("TargetButton") == null) {
    await Cysharp.Threading.Tasks.UniTask.Delay(100);
}
Selection.activeGameObject = GameObject.Find("TargetButton");
'

# Check execution results in Unity Console
uloop get-logs --search-text "FireAndForget"

Behavior

  • Compile errors ARE returned (compile check happens before return)
  • ⚠️ Runtime errors logged to Unity Console only (not returned to CLI)
  • 🔄 Use with --allow-parallel for multiple background tasks

Use Cases

  • Long-running monitoring tasks (wait for UI element to appear)
  • Scheduled actions (wait N seconds then perform action)
  • Multiple independent background tasks

Checking Background Execution Results

# View recent FireAndForget execution logs
uloop get-logs --search-text "FireAndForget"

# View all recent logs
uloop get-logs --max-count 20
uloop-execute-dynamic-code by hatayama | Agent Skills | Agent Skills