unity_execute_code
Run C# code in the Unity Editor to automate tasks, query objects, or perform one-off operations with full Unity API access. Returns results as JSON.
Instructions
Execute arbitrary C# code inside the Unity Editor. The code runs in the editor context with access to all Unity APIs. Useful for one-off operations, queries, and automation. Return values are serialized to JSON.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | C# code to execute. Must be a valid method body. Access UnityEngine and UnityEditor namespaces. Use 'return' to send data back. | |
| port | No | Target Unity instance port for parallel-safe routing. Get this from unity_select_instance. When working with multiple Unity instances, ALWAYS include this parameter. |