/script-execute
Compiles and executes C# code dynamically using Roslyn. Supports a full-code mode (default) and a body-only mode — see the skill body for the difference and for how to pass Unity object references as parameters.
$ npx -y skills add IvanMurzak/Unity-MCP --skill script-execute --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/script-execute
Context preview
The summary Claude sees to decide when to auto-load this skill.
Compiles and executes C# code dynamically using Roslyn. Supports a full-code mode (default) and a body-only mode — see the skill body for the difference and for how to pass Unity object references as parameters.
SKILL.md
script-execute.SKILL.mdname: script-execute
description: Compiles and executes C# code dynamically using Roslyn. Supports a full-code mode (default) and a body-only mode — see the skill body for the difference and for how to pass Unity object references as parameters.
Script / Execute
Modes
- **Full code mode** (default, `isMethodBody=false`): the `csharpCode` argument must define a complete class with a static method (no top-level statements).
- **Body-only mode** (`isMethodBody=true`): provide only the method body statements. The tool auto-generates the usings, class, and method header.
Passing Unity objects as parameters
Unity objects (`GameObject`, `Component`, etc.) can be passed as parameters using their `Ref` types (`GameObjectRef`, `ComponentRef`, etc.) or directly by type:
- `UnityEngine.GameObject` — resolves an actual GameObject from value `{"instanceID": N}`, `{"name": "..."}`, or `{"path": "..."}`.
- `UnityEngine.Component` (or any component subtype) — resolves from `{"instanceID": N}`.
- `AIGD.GameObjectRef` — passes a `GameObjectRef` POCO directly; the method body calls `goRef.FindGameObject()` to resolve it.
- `AIGD.ComponentRef` — passes a `ComponentRef` POCO.
- `AIGD.ObjectRef` — passes a base `ObjectRef` POCO.
How to Call
unity-mcp-cli run-tool script-execute --input '{
"csharpCode": "string_value",
"className": "string_value",
"methodName": "string_value",
"parameters": "string_value",
"isMethodBody": false
}'> For complex input (multi-line strings, code), save the JSON to a file and use: > ```bash > unity-mcp-cli run-tool script-execute --input-file args.json > ``` > > Or pipe via stdin (recommended): > ```bash > unity-mcp-cli run-tool script-execute --input-file - <<'EOF' > {"param": "value"} > EOF > ```
Troubleshooting
If `unity-mcp-cli` is not found, either install it globally (`npm install -g unity-mcp-cli`) or use `npx unity-mcp-cli` instead. Read the /unity-initial-setup skill for detailed installation instructions.
Input
| Name | Type | Required | Description | |------|------|----------|-------------| | `csharpCode` | `string` | Yes | C# code to compile and execute. In full code mode (default, isMethodBody=false): must define a complete class with a static method. Example: 'using UnityEngine; public class Script { public static void Main() { Debug.Log("Hello"); } }'. Do NOT use top-level statements. In body-only mode (isMethodBody=true): provide only the method body statements. The tool auto-generates usings, class, and method header. Example body: 'go.SetActive(false);'. Custom helper classes can still be defined inline in the body-only string after the main logic, but for complex additional class definitions use full code mode instead. | | `className` | `string` | No | The name of the class containing the method to execute. In body-only mode this becomes the generated class name. | | `methodName` | `string` | No | The name of the method to execute. Must be a static method. In body-only mode this becomes the generated method name. | | `parameters` | `any` | No | Serialized parameters to pass to the method. Each entry must specify 'name' and 'typeName'. Supported parameter types include primitives, strings, and Unity object references: - 'UnityEngine.GameObject': resolves an actual GameObject from value '{"instanceID": N}', '{"name": "..."}', or '{"path": "..."}'. - 'UnityEngine.Component' (or any component subtype): resolves from '{"instanceID": N}'. - 'AIGD.GameObjectRef': passes a GameObjectRef POCO directly; the method body calls goRef.FindGameObject() to resolve it. - 'AIGD.ComponentRef': passes a ComponentRef POCO. - 'AIGD.ObjectRef': passes a base ObjectRef POCO. If the method does not require parameters, leave this empty. | | `isMethodBody` | `boolean` | No | When true, 'csharpCode' is treated as just the method body. The tool auto-generates standard using directives (System, UnityEngine, AIGD, com.IvanMurzak.Unity.MCP.Runtime.Extensions, UnityEditor), the class definition, and the method signature (void return type). Parameters from the 'parameters' list are automatically added to the method signature using their typeName and name. When false (default), 'csharpCode' must be a complete C# compilation unit with class and method definitions. |
Input JSON Schema
{
"type": "object",
"properties": {
"csharpCode": {
"type": "string"
},
"className": {
"type": "string"
},
"methodName": {
"type": "string"
},
"parameters": {
"$ref": "#/$defs/com.IvanMurzak.ReflectorNet.Model.SerializedMemberList"
},
"isMethodBody": {
"type": "boolean"
}
},
"$defs": {
"com.IvanMurzak.ReflectorNet.Model.SerializedMemberList": {
"type": "array",
"items": {
"$ref": "#/$defs/com.IvanMurzak.ReflectorNet.Model.SerializedMember"
}
},
"com.IvanMurzak.ReflectorNet.Model.SerializedMember": {
"type": "object",
"properties": {
"typeName": {
"type": "string",
"description": "Full type name. Eg: 'System.String', 'System.Int32', 'UnityEngine.Vector3', etc."
},
"name": {
"type": "string",
"description": "Object name."
},
"value": {
"description": "Value of the object, serialized as a non stringified JSON element. Can be null if the value is not set. Can be default value if the value is an empty object or array json."
},
"fields": {
"type": "array",
"items": {
"$ref": "#/$defs/com.IvanMurzak.ReflectorNet.Model.SerializedMember",
"description": "Nested field value."
},
"description": "Fields of the object, serialized as a list of 'SerializedMember'."
},
"props": {
"type": "array",
"items": {
"$ref": "#/$defs/com.IvanMurzak.ReflectorNet.Model.SerializedMember",
"description": "Nested propertyRead more
name: script-execute description: Compiles and executes C# code dynamically using Roslyn. Supports a full-code mode (default) and a body-only mode — see the skill body for the difference and for how to pass Unity object references as parameters.
Script / Execute
Modes
- **Full code mode** (default, `isMethodBody=false`): the `csharpCode` argument must define a complete class with a static method (no top-level statements).
- **Body-only mode** (`isMethodBody=true`): provide only the method body statements. The tool auto-generates the usings, class, and method header.
Passing Unity objects as parameters
Unity objects (`GameObject`, `Component`, etc.) can be passed as parameters using their `Ref` types (`GameObjectRef`, `ComponentRef`, etc.) or directly by type:
- `UnityEngine.GameObject` — resolves an actual GameObject from value `{"instanceID": N}`, `{"name": "..."}`, or `{"path": "..."}`.
- `UnityEngine.Component` (or any component subtype) — resolves from `{"instanceID": N}`.
- `AIGD.GameObjectRef` — passes a `GameObjectRef` POCO directly; the method body calls `goRef.FindGameObject()` to resolve it.
- `AIGD.ComponentRef` — passes a `ComponentRef` POCO.
- `AIGD.ObjectRef` — passes a base `ObjectRef` POCO.
How to Call
unity-mcp-cli run-tool script-execute --input '{
"csharpCode": "string_value",
"className": "string_value",
"methodName": "string_value",
"parameters": "string_value",
"isMethodBody": false
}'> For complex input (multi-line strings, code), save the JSON to a file and use: > ```bash > unity-mcp-cli run-tool script-execute --input-file args.json > ``` > > Or pipe via stdin (recommended): > ```bash > unity-mcp-cli run-tool script-execute --input-file - <<'EOF' > {"param": "value"} > EOF > ```
Troubleshooting
If `unity-mcp-cli` is not found, either install it globally (`npm install -g unity-mcp-cli`) or use `npx unity-mcp-cli` instead. Read the /unity-initial-setup skill for detailed installation instructions.
Input
| Name | Type | Required | Description | |------|------|----------|-------------| | `csharpCode` | `string` | Yes | C# code to compile and execute. In full code mode (default, isMethodBody=false): must define a complete class with a static method. Example: 'using UnityEngine; public class Script { public static void Main() { Debug.Log("Hello"); } }'. Do NOT use top-level statements. In body-only mode (isMethodBody=true): provide only the method body statements. The tool auto-generates usings, class, and method header. Example body: 'go.SetActive(false);'. Custom helper classes can still be defined inline in the body-only string after the main logic, but for complex additional class definitions use full code mode instead. | | `className` | `string` | No | The name of the class containing the method to execute. In body-only mode this becomes the generated class name. | | `methodName` | `string` | No | The name of the method to execute. Must be a static method. In body-only mode this becomes the generated method name. | | `parameters` | `any` | No | Serialized parameters to pass to the method. Each entry must specify 'name' and 'typeName'. Supported parameter types include primitives, strings, and Unity object references: - 'UnityEngine.GameObject': resolves an actual GameObject from value '{"instanceID": N}', '{"name": "..."}', or '{"path": "..."}'. - 'UnityEngine.Component' (or any component subtype): resolves from '{"instanceID": N}'. - 'AIGD.GameObjectRef': passes a GameObjectRef POCO directly; the method body calls goRef.FindGameObject() to resolve it. - 'AIGD.ComponentRef': passes a ComponentRef POCO. - 'AIGD.ObjectRef': passes a base ObjectRef POCO. If the method does not require parameters, leave this empty. | | `isMethodBody` | `boolean` | No | When true, 'csharpCode' is treated as just the method body. The tool auto-generates standard using directives (System, UnityEngine, AIGD, com.IvanMurzak.Unity.MCP.Runtime.Extensions, UnityEditor), the class definition, and the method signature (void return type). Parameters from the 'parameters' list are automatically added to the method signature using their typeName and name. When false (default), 'csharpCode' must be a complete C# compilation unit with class and method definitions. |
Input JSON Schema
{
"type": "object",
"properties": {
"csharpCode": {
"type": "string"
},
"className": {
"type": "string"
},
"methodName": {
"type": "string"
},
"parameters": {
"$ref": "#/$defs/com.IvanMurzak.ReflectorNet.Model.SerializedMemberList"
},
"isMethodBody": {
"type": "boolean"
}
},
"$defs": {
"com.IvanMurzak.ReflectorNet.Model.SerializedMemberList": {
"type": "array",
"items": {
"$ref": "#/$defs/com.IvanMurzak.ReflectorNet.Model.SerializedMember"
}
},
"com.IvanMurzak.ReflectorNet.Model.SerializedMember": {
"type": "object",
"properties": {
"typeName": {
"type": "string",
"description": "Full type name. Eg: 'System.String', 'System.Int32', 'UnityEngine.Vector3', etc."
},
"name": {
"type": "string",
"description": "Object name."
},
"value": {
"description": "Value of the object, serialized as a non stringified JSON element. Can be null if the value is not set. Can be default value if the value is an empty object or array json."
},
"fields": {
"type": "array",
"items": {
"$ref": "#/$defs/com.IvanMurzak.ReflectorNet.Model.SerializedMember",
"description": "Nested field value."
},
"description": "Fields of the object, serialized as a list of 'SerializedMember'."
},
"props": {
"type": "array",
"items": {
"$ref": "#/$defs/com.IvanMurzak.ReflectorNet.Model.SerializedMember",
"description": "Nested propertyGet up and running in three steps: Install plugin — download the .unitypackage installer or run openupm add com.ivanmurzak.unity.mcp Alternative: npx unity-mcp-cli install-plugin ./MyUnityProject — see CLI documentation Pick an AI agent — Claude Code, Claude
Repo: IvanMurzak/Unity-MCP
Other skills on ivanmurzak-unity-mcp.
- /build-cli
Build the unity-mcp-cli TypeScript CLI tool and link it globally for terminal use.
Open skill - /github-pr-review-fix
Review and resolve PR comments from GitHub. Validates each comment, fixes legitimate issues.
Open skill - /assets-copy
Copy assets at given paths and store them at new paths. Refreshes the AssetDatabase at the end. Use 'assets-find' to locate the source assets first.
Open skill - /assets-create-folder
Create a new folder under a parent folder inside 'Assets/'. The parent path must start with 'Assets/' and every intermediate folder in it must already exist. Refreshes the AssetDatabase at the end and returns the GUID(s) of the created folder(s).
Open skill - /assets-delete
Delete the assets at the given project paths. Refreshes the AssetDatabase at the end. Use 'assets-find' to locate the assets first.
Open skill - /assets-find-built-in
Search the built-in assets of the Unity Editor (located at Resources/unity_builtin_extra). Filters by name and/or type; built-in assets have no GUID so GUID-based lookups are not supported.
Open skill

