execute_code
Run C# code in the Unity Editor to manipulate scenes, assets, and game objects, enabling automated testing and scene adjustments.
Instructions
Execute arbitrary C# code in the Unity Editor context. This is the most powerful tool — it can do anything the Unity Editor API allows.
The code runs with full access to UnityEngine, UnityEditor, System, and all project assemblies.
For simple expressions, just provide the expression (e.g., "Selection.activeGameObject.name"). For multi-statement code, write full C# statements. A return statement determines the output. For void operations, the code runs and any Debug.Log output is captured.
Pre-imported namespaces: System, System.Collections.Generic, System.Linq, System.Reflection, System.IO, UnityEngine, UnityEditor, UnityEditor.SceneManagement, UnityEngine.SceneManagement, UnityEngine.UI
Examples:
"PlayerSettings.productName" → returns product name
"GameObject.FindObjectsOfType().Length" → returns camera count
"var go = new GameObject("MyObject"); return go.name;" → creates object, returns name
"Debug.Log("Hello"); return Selection.objects.Length;" → logs + returns count
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | C# code to execute. Can be a single expression, multiple statements, or a full class with an Execute method. |