home / skills / dev-gom / claude-code-marketplace / unity-uitoolkit

This skill helps you accelerate Unity UI Toolkit development by guiding UXML, USS, and VisualElement patterns for efficient, maintainable interfaces.

npx playbooks add skill dev-gom/claude-code-marketplace --skill unity-uitoolkit

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
2.8 KB
---
name: Unity UI Toolkit
description: Assists with Unity UI Toolkit development - UXML structure, USS styling, C# VisualElement manipulation, data binding, and custom controls. Use when implementing UI Toolkit interfaces.
allowed-tools: Read, Write, Glob
---

# Unity UI Toolkit

Assists with Unity UI Toolkit development including UXML markup, USS styling, C# VisualElement API, and modern UI patterns.

## What This Skill Helps With

### UXML Structure
- Proper element hierarchy and naming conventions
- Common controls: TextField, Button, Toggle, Slider, ObjectField, ListView
- Layout containers: VisualElement, ScrollView, Foldout, TwoPaneSplitView
- Data-driven UI with templates and bindings

### USS Styling
- Class-based styling and selectors
- Flexbox layout (flex-direction, justify-content, align-items)
- USS variables and dark theme optimization
- Pseudo-classes (:hover, :active, :disabled)
- Transitions and animations

### C# VisualElement API
- Query API: `rootElement.Q<Button>("my-button")`
- Event handling: `.clicked +=` and `.RegisterValueChangedCallback()`
- Dynamic UI creation with constructors
- Data binding with `Bind()` and `SerializedObject`

### Best Practices
- UXML for structure, USS for styling, C# for logic
- Name elements for Query API access
- Use classes for styling, not inline styles
- Cache VisualElement references in fields
- Proper event cleanup in `OnDestroy()`

## Common Patterns

**Editor Window Setup:**
```csharp
public void CreateGUI() {
    var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("path/to.uxml");
    visualTree.CloneTree(rootVisualElement);

    var button = rootVisualElement.Q<Button>("my-button");
    button.clicked += OnButtonClick;
}
```

**USS Class Toggle:**
```csharp
element.AddToClassList("active");
element.RemoveFromClassList("active");
element.ToggleInClassList("active");
```

**Data Binding:**
```csharp
var so = new SerializedObject(target);
rootVisualElement.Bind(so);
```

## Unity Version Requirements

- **Unity 2021.2+** for runtime UI Toolkit
- **Unity 2019.4+** for editor-only UI Toolkit (limited features)

See [ui-toolkit-reference.md](ui-toolkit-reference.md) for complete API documentation.

## When to Use vs Other Components

**Use this Skill when**: Building UI Toolkit interfaces, writing UXML/USS, or manipulating VisualElements in C#

**Use unity-ui-selector skill when**: Choosing between UGUI and UI Toolkit for a project

**Use @unity-scripter agent when**: Implementing complex UI logic or custom VisualElement controls

**Use EditorScriptUIToolkit templates when**: Generating new UI Toolkit editor windows with UXML/USS files

## Related Skills

- **unity-ui-selector**: Helps choose between UGUI and UI Toolkit
- **unity-template-generator**: Generates UI Toolkit editor script templates
- **unity-script-validator**: Validates UI Toolkit code patterns

Overview

This skill assists developers building Unity UI Toolkit interfaces by providing focused guidance on UXML structure, USS styling, C# VisualElement manipulation, data binding, and custom control patterns. It targets both editor and runtime UI workflows and emphasizes clear separation of concerns: UXML for structure, USS for styling, and C# for logic. Useful for implementing maintainable, data-driven UI with modern Unity versions.

How this skill works

The skill inspects typical UI Toolkit tasks and gives concrete patterns: correct UXML hierarchies and element names, USS class usage and flexbox layout, common VisualElement queries and event wiring in C#, and binding SerializedObject data to the visual tree. It explains runtime vs editor constraints, version requirements, and provides snippets for cloning UXML, toggling classes, registering callbacks, and binding data sources.

When to use it

  • Creating editor windows or runtime UI using Unity UI Toolkit (UXML/USS).
  • Structuring UXML templates and naming elements for reliable Query API access.
  • Implementing styling with USS classes, flexbox layout, and theme variables.
  • Wiring up C# logic: event handlers, dynamic element creation, and data binding.
  • Building custom VisualElement controls or optimizing UI performance.

Best practices

  • Keep UXML for hierarchy, USS for styles, and C# for behavior to maintain separation of concerns.
  • Name key elements in UXML to use rootVisualElement.Q<T>("name") reliably.
  • Prefer class-based USS styling and ToggleInClassList for state changes instead of inline styles.
  • Cache frequently accessed VisualElement references in fields and unregister events in OnDestroy.
  • Use SerializedObject.Bind(rootVisualElement) for consistent inspector-style data binding.

Example use cases

  • Create an editor window: load a VisualTreeAsset, CloneTree(rootVisualElement), query controls, and wire button.clicked handlers.
  • Style a responsive inspector panel using USS flexbox rules, pseudo-classes, and theme variables for dark mode.
  • Implement a ListView with data templates and bind it to a SerializedObject collection for editable lists.
  • Build a custom compound control by composing VisualElement children in C# and exposing USS classes for styling.
  • Toggle state visuals using AddToClassList/RemoveFromClassList or ToggleInClassList for animated transitions.

FAQ

Which Unity versions support runtime UI Toolkit features?

Use Unity 2021.2 or later for supported runtime UI Toolkit; editor-only features are available from 2019.4 with limitations.

Should I use UXML or create elements in C#?

Prefer UXML for static structure and readability; use C# for dynamic content, runtime creation, and behaviors that require logic.