Skip to main content

ui_document

Auto-generated from the Python tool registry. Do not hand-edit outside <!-- examples:start --><!-- examples:end --> blocks — the generator (tools/generate_docs_reference.py) will overwrite them.

Group: ui  ·  Module: services.registry.capability_adapter

Maturity: stable (support status; independent of enabled state, readiness and permissions).

Description​

Attach UI documents and configure Panel Settings.

Parameters​

NameTypeRequiredDescription
actionLiteral['attach_ui_document', 'detach_ui_document', 'create_panel_settings', 'update_panel_settings']yesFeature action to perform.
pathstr | None—Assets-relative path (e.g., 'Assets/UI/MainMenu.uxml' or 'Assets/UI/Styles.uss'). For render_ui: optional UXML path to render directly without a scene GameObject.
targetstr | None—Target GameObject name or path for attach_ui_document / get_visual_tree / render_ui.
component_typeLiteral['auto', 'ui_document', 'panel_renderer'] | None—UI component for attach/detach, get_visual_tree, modify_visual_element and render_ui. Default auto preserves an existing UIDocument, otherwise resolves PanelRenderer; new attachments prefer PanelRenderer when available and fall back to UIDocument. Explicit panel_renderer selection requires the Editor's native PanelRenderer API.
source_assetstr | None—Path to UXML VisualTreeAsset (e.g., 'Assets/UI/MainMenu.uxml').
panel_settingsstr | None—Path to PanelSettings asset. Auto-creates default if omitted.
sort_orderint | None—UI component sort order (default 0).
scale_modeLiteral['ConstantPixelSize', 'ConstantPhysicalSize', 'ScaleWithScreenSize'] | None—Panel scale mode. Legacy shorthand; prefer using 'settings' dict.
reference_resolutiondict[str, int] | None—Reference resolution as {width, height}. Legacy shorthand; prefer using 'settings' dict.
settingsdict[str, Any] | None—Generic PanelSettings properties dict for create_panel_settings. Keys: scaleMode (ConstantPixelSize|ConstantPhysicalSize|ScaleWithScreenSize), referenceResolution ({width,height}), screenMatchMode (MatchWidthOrHeight|ShrinkToFit|ExpandToFill), match (0-1 float), referenceDpi, fallbackDpi, sortingOrder, targetDisplay, clearColor (bool), colorClearValue (#RRGGBB or {r,g,b,a}), clearDepthStencil, themeStyleSheet (asset path), dynamicAtlasSettings ({minAtlasSize,maxAtlasSize,maxSubTextureSize,activeFilters}).
unity_instancestr | int | None—Target Unity instance for this call: Name@hash or hash prefix; an integer selects only that exact port over stdio and is rejected over HTTP. Read mcpforunity://instances for available targets. Omit to use the legacy active selection or the sole available instance.

Returns​

A dict containing the Unity response. The exact shape depends on the action.

Examples​

Attach an existing UXML asset to a named GameObject using UIDocument explicitly. Use the correct source and an existing PanelSettings asset so the operation uses that panel configuration.

MCP arguments
{
"action": "attach_ui_document",
"target": "HUD",
"component_type": "ui_document",
"source_asset": "Assets/UI/HUD.uxml",
"panel_settings": "Assets/UI/MainPanel.asset"
}