Skip to main content

ui_element

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​

Change a visual element's text, classes, style or state.

Parameters​

NameTypeRequiredDescription
actionLiteral['modify_visual_element']yesFeature action to perform.
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.
element_namestr | None—Visual element name. Legacy first match unless strict_name=true. Optional exact name guard with element_path or element_id. For modify_visual_element.
element_pathstr—Current snapshot/content-container child-index path, e.g. '/0/1'; empty string selects root. Zero-based decimal indices, no leading zeros. No persistent identity or replacement detection. Mutually exclusive with element_id; no name fallback. Omit when unused; explicit null is invalid.
element_idstr—Exact current UI Toolkit snapshot node ID. Uses the snapshot's auto-selected UI component; use element_path for another component_type. Semantic path, not a persistent handle; same-path replacement is not detected. No name fallback. Omit when unused; null/empty invalid.
strict_namebool | None—Require exactly one element_name match over the UQuery root and physical control internals. Default false keeps legacy first match. Active initialized UI required; bounded scan may refuse. Explicit selectors take precedence; element_name then guards the selected name.
textstr | None—New text content for Label/Button elements. For modify_visual_element.
add_classeslist[str] | None—USS class names to add to the element. For modify_visual_element.
remove_classeslist[str] | None—USS class names to remove from the element. For modify_visual_element.
toggle_classeslist[str] | None—USS class names to toggle on the element. For modify_visual_element.
styledict[str, Any] | None—Inline styles for modify_visual_element. Legacy scalar values remain supported. Typed lengths: {'value': 50, 'unit': '%'} or {'keyword': 'auto'} where supported. Inspect data.style_results for every applied/rejected entry and final inline overrides.
enabledbool | None—Set element enabled/disabled state. For modify_visual_element.
visiblebool | None—Set element visibility (display: flex/none). For modify_visual_element.
tooltipstr | None—Set element tooltip text. For modify_visual_element.
strict_stylebool—Reject every requested mutation before application if any inline style is rejected. Only modify_visual_element; default false preserves lenient compatibility. Validation is not callback rollback.
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​

Change the live text of one named UI Toolkit Label in an initialized HUD. Use the actual scene object and element name. strict_name rejects an ambiguous match.

MCP arguments
{
"action": "modify_visual_element",
"target": "HUD",
"element_name": "status-label",
"strict_name": true,
"text": "Ready"
}