Tools: Window Management
Relevant source files
The following files were used as context for generating this wiki page:
The Window Management tools provide capabilities for AI agents to interact with and observe the state of the Unity Editor's graphical user interface. These tools are essential for tasks that require visual feedback or ensuring the editor is the active application. The two primary tools in this category are focus-window and capture-window.
These features allow an AI to perform actions like bringing the Unity Editor to the foreground after another process takes focus, or capturing the state of a window (like the Console or Scene view) to get visual context. This is a key part of enabling an autonomous development loop where the AI can see the results of its actions.
Sources: Packages/src/README.md:143-147, 156-162
focus-window Tool
This tool brings the Unity Editor window to the foreground, making it the active application on the user's desktop. It is particularly useful for keeping visual feedback in sync when other applications might steal focus. The functionality is supported on macOS and Windows, but is currently unsupported on Linux.
Sources: Packages/src/README.md:143-147, Packages/src/Editor/Api/McpTools/FocusUnityWindow/FocusUnityWindowTool.cs
Execution Flow
The focus-window tool's execution is straightforward. It receives the request and, based on the operating system, attempts to focus the main Unity Editor window.
This diagram shows the simple conditional logic of the focus-window tool based on the operating system.
Sources: Packages/src/README.md:147, Packages/src/Editor/Api/McpTools/FocusUnityWindow/FocusUnityWindowTool.cs:17-25
API Specification
The tool takes no parameters and returns a simple success status.
| Field | Type | Description |
|---|---|---|
Success | boolean | true if the operation was successful, false otherwise. |
Message | string | A message describing the result of the operation. |
ErrorMessage | string | An error message if the operation failed. |
Sources: Packages/src/TOOL_REFERENCE.md:271-277
capture-window Tool
The capture-window tool captures a specified EditorWindow as a PNG image. This allows an AI to get visual feedback on the state of the editor, such as viewing the console logs, inspecting the scene, or checking game output.
Sources: Packages/src/README.md:156-162, Packages/src/Editor/Api/McpTools/CaptureWindow/CaptureWindowTool.cs
Architecture and Flow
The CaptureWindowTool class orchestrates the window capture process. Upon execution, it uses the EditorWindowCaptureUtility to find and capture the target window(s). The resulting texture is then encoded to PNG and saved to a dedicated output directory.
The following sequence diagram illustrates the process:
This diagram shows the sequence of operations when the capture-window tool is executed, from finding the window to saving the capture to disk.
Sources: Packages/src/Editor/Api/McpTools/CaptureWindow/CaptureWindowTool.cs:22-95
Output Management
Captured images are saved in a structured manner to avoid cluttering the project root and to provide clear, identifiable filenames.
- Directory:
{project_root}/.uloop/outputs/UnityWindowCaptures/ - Filename Format:
{sanitized_window_name}_{timestamp}.png - Multiple Windows: If multiple windows match the name (e.g., several "Inspector" windows), they are numbered:
{sanitized_window_name}_{index}_{timestamp}.png.
Sources: Packages/src/Editor/Api/McpTools/CaptureWindow/CaptureWindowTool.cs:17, 51-54, 69-72
API Specification
The tool offers several parameters to control the capture process.
| Parameter | Type | Description | Default |
|---|---|---|---|
WindowName | string | The name of the window to capture (title bar/tab text). | (required) |
MatchMode | enum | How to match the window name: Exact, Prefix, Contains. Case-insensitive. | Exact |
ResolutionScale | float | The resolution scale of the capture, between 0.1 and 1.0. | 1.0 |
The response contains a list of successfully captured windows.
| Field | Type | Description |
|---|---|---|
CapturedWindows | array | A list of objects, each describing a captured window. |
- FilePath | string | The full path to the saved PNG file. |
- FileSize | long | The size of the file in bytes. |
- Width | int | The width of the captured image. |
- Height | int | The height of the captured image. |
Sources: Packages/src/TOOL_REFERENCE.md:156-162, Packages/src/Editor/Api/McpTools/CaptureWindow/CaptureWindowTool.cs:12, 24, 98-106
EditorWindowCaptureUtility
This utility class provides the core logic for finding and capturing EditorWindow instances. It is used exclusively by the CaptureWindowTool.
Sources: Packages/src/Editor/Utils/EditorWindowCaptureUtility.cs
Key Methods
-
FindWindowsByName(string name, MatchMode mode): This method iterates through all openEditorWindowobjects and returns an array of windows that match the given name and match mode. The matching is case-insensitive.
Sources: Packages/src/Editor/Utils/EditorWindowCaptureUtility.cs:16-41 -
CaptureWindowAsync(EditorWindow window, float scale, CancellationToken ct): This asynchronous method captures the content of a givenEditorWindow. It creates aRenderTexture, renders the window's GUI into it, and then converts it to aTexture2D. Thescaleparameter allows for capturing at a lower resolution to save space.
Sources: Packages/src/Editor/Utils/EditorWindowCaptureUtility.cs:43-76
Match Modes
The MatchMode enum defines how the WindowName parameter is interpreted when searching for windows.
| Mode | Description |
|---|---|
Exact | The window title must be an exact case-insensitive match. |
Prefix | The window title must start with the specified name, case-insensitively. |
Contains | The window title must contain the specified name, case-insensitively. |
Sources: Packages/src/Editor/Utils/EditorWindowCaptureUtility.cs:9-14