Back to Unity Mcp

manage_ui

website/docs/reference/tools/ui/manage_ui.md

9.7.16.3 KB
Original Source

manage_ui

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.tools.manage_ui

Description

Manages Unity UI Toolkit elements (UXML documents, USS stylesheets, UIDocument components). Read-only actions: ping, read, get_visual_tree, list. Modifying actions: create, update, delete, attach_ui_document, detach_ui_document, create_panel_settings, update_panel_settings, modify_visual_element. Visual actions: render_ui (captures UI panel to a PNG screenshot for self-evaluation). Structural actions: link_stylesheet (adds a Style src reference to a UXML file).

UI Toolkit workflow:

  1. Use list to discover existing UI assets
  2. Create a UXML file (structure, like HTML)
  3. Create a USS file (styling, like CSS)
  4. Link stylesheet to UXML via link_stylesheet
  5. Attach UIDocument to a GameObject with the UXML source
  6. Use get_visual_tree to inspect the result
  7. Use modify_visual_element to change text, classes, or inline styles on live elements
  8. Use render_ui to capture a visual preview for self-evaluation
    • In play mode: first call queues a WaitForEndOfFrame screen capture and returns pending=true; call render_ui a second time to retrieve the saved PNG (hasContent will be true).
    • In editor mode: assigns a RenderTexture to PanelSettings (best-effort; may stay blank).
  9. Use detach_ui_document to remove UIDocument from a GameObject
  10. Use delete to remove .uxml/.uss files

Important: Always use ui:Style (with the ui: namespace prefix) in UXML, not bare <Style>. UI Builder will fail to open files that use <Style> without the prefix.

Parameters

NameTypeRequiredDescription
actionLiteral['ping', 'create', 'read', 'update', 'delete', 'attach_ui_document', 'detach_ui_document', 'create_panel_settings', 'update_panel_settings', 'get_visual_tree', 'render_ui', 'link_stylesheet', 'list', 'modify_visual_element']yesAction to perform.
pathstr | NoneAssets-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.
contentsstr | NoneFile content (UXML or USS markup). Plain text - encoding handled automatically.
targetstr | NoneTarget GameObject name or path for attach_ui_document / get_visual_tree / render_ui.
source_assetstr | NonePath to UXML VisualTreeAsset (e.g., 'Assets/UI/MainMenu.uxml').
panel_settingsstr | NonePath to PanelSettings asset. Auto-creates default if omitted.
sort_orderint | NoneUIDocument sort order (default 0).
scale_modeLiteral['ConstantPixelSize', 'ConstantPhysicalSize', 'ScaleWithScreenSize'] | NonePanel scale mode. Legacy shorthand; prefer using 'settings' dict.
reference_resolutiondict[str, int] | NoneReference resolution as {width, height}. Legacy shorthand; prefer using 'settings' dict.
settingsdict[str, Any] | NoneGeneric 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}).
max_depthint | NoneMax depth to traverse visual tree (default 10).
widthint | NoneRender width in pixels (default 1920). For render_ui.
heightint | NoneRender height in pixels (default 1080). For render_ui.
include_imagebool | NoneReturn inline base64 PNG in the response (default false). For render_ui.
max_resolutionint | NoneMax resolution for inline base64 image (default 640). For render_ui.
screenshot_file_namestr | NoneCustom file name for the render output (default: auto-generated). For render_ui.
output_folderstr | NoneOptional folder for the render output. Project-relative (e.g. 'Assets/Screenshots' or 'Captures') or absolute path inside the project. Overrides the user's Editor preference. If omitted, falls back to the Editor preference, then to the built-in default (Assets/Screenshots). For render_ui.
stylesheetstr | NonePath to USS stylesheet to link (e.g., 'Assets/UI/Styles.uss'). For link_stylesheet.
filter_typestr | NoneFilter UI assets by type: 'uxml', 'uss', 'PanelSettings', or omit for all. For list.
page_sizeint | NoneNumber of results per page (default 50). For list.
page_numberint | NonePage number, 1-based (default 1). For list.
element_namestr | NoneName of the visual element to modify (the 'name' attribute in UXML). For modify_visual_element.
textstr | NoneNew text content for Label/Button elements. For modify_visual_element.
add_classeslist[str] | NoneUSS class names to add to the element. For modify_visual_element.
remove_classeslist[str] | NoneUSS class names to remove from the element. For modify_visual_element.
toggle_classeslist[str] | NoneUSS class names to toggle on the element. For modify_visual_element.
styledict[str, Any] | NoneInline styles to set (e.g., {'backgroundColor': '#FF0000', 'fontSize': 24}). For modify_visual_element.
enabledbool | NoneSet element enabled/disabled state. For modify_visual_element.
visiblebool | NoneSet element visibility (display: flex/none). For modify_visual_element.
tooltipstr | NoneSet element tooltip text. For modify_visual_element.

Returns

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

Examples

<!-- examples:start -->

No examples yet. Add usage examples here — they will be preserved across regenerations.

<!-- examples:end -->