Understand existing Unity UI Toolkit code, make targeted edits, generate new UXML/USS files, Manipulators, and handle UI runtime binding.
References
Read these as needed:
references/uss-guide.md — USS patterns and examples
references/svg-icons.md — SVG icon generation (only when generating icons)
references/common-issues.md — Common mistakes to avoid
references/ui-runtime-binding.md — Patterns and guide to bind data to UI at runtime (only when requested or when bindings are involved)
references/painter2d.md — Painter2D API for custom visuals: gradients, shapes, arcs, procedural drawing (read this whenever gradients, custom shapes, progress rings, procedural drawing, or any visual beyond what USS can express is needed)
references/pointermanipulator-guide.md — Patterns and guide to create and use Manipulators (only when requested or when manipulators are involved). This helps with setting up drag and drop features or simple event handling for a Visual Element.
references/custom-elements.md — Custom UI Element patterns and guide to create reusable components with UXML, USS, and C#. This helps with creating complex UI components for reuse across the project.
Paths are relative to this skill's folder — read references/uss-guide.md directly.
Understanding
When explaining UI structure, use this format:
[ElementType] name="elementName" class="class1 class2"
├── [ChildType] name="childName"
│ └── [GrandchildType]
└── [ChildType] class="another-class"
Editing
Common edit requests:
| Request |
Action |
| "Change button color" |
Edit USS selector for that button |
| "Add a label here" |
Add element to UXML at specified location |
| "Make this bigger" |
Edit width/height in USS |
| "Hide this element" |
Add display: none to USS or remove from UXML |
| "Rename this element" |
Update name attribute in UXML |
Don't over-edit:
- Change only what's requested
- Preserve formatting and structure
- Don't "improve" unrelated code
- Don't add comments unless asked
- For targeted changes, prefer modifying specific elements or selectors over rewriting entire files — but use judgment; if a change touches most of the file, a rewrite may be cleaner
- Be careful not to accidentally drop existing elements, styles, or references when making edits
- When editing USS, focus on the properties and selectors relevant to the request — avoid unnecessary reorganization, but restructure if the change genuinely requires it
Validation
There is no way to validate UXML or USS from outside the Editor — Unity parses these
files on import and reports problems in the Console. Write the files, then have the
user check the result.
Workflow:
- Write the complete file to its target path in the project. Do not write partial or
draft content — a half-written UXML file is a parse error the moment the Editor
picks it up.
- Ask the user to focus the Unity Editor. That triggers a reimport of the changed
assets.
- Ask them to report anything in the Console. UXML parse errors name the file and
line; USS problems appear as warnings about unknown properties or selectors.
- Fix what they report and repeat from step 1.
Because feedback costs a user round-trip, get it right the first time:
- Finish all files before asking the user to check, so one reimport covers everything
rather than one per file.
- Re-read
references/uss-guide.md and references/common-issues.md before writing,
rather than after an error comes back.
- Watch for the mistakes that survive a parse but render wrong — those will not appear
in the Console at all, so the user has to eyeball the UI.
references/common-issues.md
lists them.
Generation
When creating new UI:
Generate only what is requested:
| Request |
Output |
| USS only |
.uss file only |
| UXML only |
.uxml file only |
| UI screen / menu / panel |
.uss + .uxml only |
| "with code" / "with logic" / "functional" |
.uss + .uxml + .cs |
These do NOT imply C#:
- "proper buttons" → well-styled Button elements
- "currency display" → a Label element
- "working UI" → valid UXML/USS that renders
- "inventory screen" → visual layout only
- "inventory system" / "equipment system" / "crafting system" → Ask: "Should items be draggable?" If yes, see
references/pointermanipulator-guide.md for patterns
Generation workflow:
- Analyze — Determine exactly what files are needed. No extras.
- Search — Find existing USS, UXML, assets. Don't assume paths.
- Follow project patterns — Match folder structure and naming conventions.
- Reuse — Check for shared stylesheets. Reuse if appropriate.
- Write USS first — Verify against restrictions below.
- Write UXML — Reference the USS, verify structure.
- Write the files out complete — never partial content; see Validation above for
how errors come back and why one round of files beats several.
- Scene setup — Assign PanelSettings if adding UI to scene.
- Data binding — If requested, add C# script with runtime data binding patterns (see
references/ui-runtime-binding.md). Generate the scriptable object asset if needed. Assign the asset to the UI element root in UXML or via datasource in C#.
Color, visibility, and specification rules:
- Ensure text is readable by default: When choosing colors, ensure text contrasts with its background — but respect intentional low-contrast uses (disabled states, placeholder text, decorative elements). When using design tokens, check that text and background variables provide adequate contrast.
- Honor exact values: User-specified hex colors, pixel dimensions, spacing — use exactly as given. Do not approximate or substitute.
Styling / Theme
When styling UI or adjusting theme make sure to not only apply to the elements directly in the current UXML but also to the core elements of UI Toolkit which are composed of several child elements usually.
Conventions
Follow project patterns first. Search existing files before applying defaults.
| Type |
Convention |
Good |
Bad |
name attribute |
camelCase |
submitButton |
submit-button |
class attribute / USS |
kebab-case |
.submit-button |
.submitButton |
| File paths |
Feature folders |
Assets/UI/Inventory/ |
Assets/Scripts/UI/ |
Output format:
<ui:UXML>...</ui:UXML>
.class { ... }
USS Restrictions
Unity's USS is a subset of CSS. These properties do NOT exist — NEVER use them:
| NEVER Use |
Use Instead |
border shorthand |
border-width, border-color separately |
gap |
margin on children |
z-index |
DOM order or parent nesting |
pointer-events |
picking-mode UXML attribute |
filter |
Not supported |
outline |
border-* properties |
box-shadow |
Nested elements or background image |
:first-child, :last-child, :nth-child |
Explicit classes |
[attribute] selectors |
Explicit classes |
transition-property: <value> |
Omit entirely, or none/initial/inherit only |
linear-gradient(), radial-gradient() |
Custom VisualElement with Painter2D (see references/painter2d.md) |
Inline styles: NEVER use style="..." in UXML. All styling in USS only.
External URLs: NEVER use url() with external paths. Only url("project://database/Assets/...").
Prefer flexible layouts over hardcoded sizes:
- Use
flex-grow, flex-shrink, or % instead of fixed width/height values
- Let elements flow naturally and be constrained by their parent container
- Set explicit pixel sizes only on root containers or when a fixed size is truly required
- Child elements should adapt to available space rather than define their own dimensions
USS Brevity
- No default values (
flex-direction: column is default)
- No default fonts
- No redundant constraints (
width: 100px doesn't need min-width/max-width)
- No overlapping properties (
flex: 1 already sets grow/shrink)
- Simplest selector that works
- Never duplicate selectors
UXML
Every file must:
- Declare namespace:
<ui:UXML xmlns:ui="UnityEngine.UIElements">
- Link stylesheet(s):
<ui:Style src="Screen.uss" />
- Have exactly one top-level container
- No
style="..." attributes — use USS only
<ui:UXML xmlns:ui="UnityEngine.UIElements">
<ui:Style src="Panel.uss" />
<ui:VisualElement name="root" class="panel">
<!-- content -->
</ui:VisualElement>
</ui:UXML>
Events and Interactivity
- Use Pointer Manipulators for event handling and interactivity on a VisualElement (see
references/pointermanipulator-guide.md)
- If drag and drop is requested then write a pointer Manipulator and attach it to the relevant Visual Element in UXML or via C#.
- For simple click events, you can use the
clickable manipulator in UXML
- For more advanced interactions, create use more traditional event callbacks in C# and attach them to elements as needed
For inventory and crafting systems:
- When users request an "inventory system", "equipment system", or "crafting system", ask explicitly: "Should players be able to drag and drop items?"
- If yes, read
references/pointermanipulator-guide.md for inventory/crafting-specific patterns
- If no or unclear, create static layout only
Assets
Do NOT reference UnityDefaultRuntimeTheme.tss or Unity's built-in theme icons.
Icon priority:
- Reuse existing project icons
- Generate SVG (see
references/svg-icons.md)
- Image generators (last resort)
Reference format:
background-image: url("project://database/Assets/UI/Textures/icon.png");
Scene Setup
PanelSettings is required — UI won't render without it.
- Search for existing PanelSettings asset
- If none, create generic:
Assets/UI/PanelSettings.asset
- Assign to UIDocument's
Panel Settings field
Skip for Editor UI (EditorWindow, PropertyDrawer).
C# (Only When Requested)
- Style via USS classes (
AddToClassList()) — never use element.style.* as inline styles have higher specificity than USS selectors, making them impossible to override via stylesheets, and add per-element memory overhead
- UITK uses TextCore text assets — use
FontAsset, TextStyleSheet, and TextSettings, not their TextMeshPro equivalents (TMP_FontAsset, etc.)
- Place scripts in same folder as UXML/USS
1---2name: ui-uitk3description: Unity UI Toolkit expert for Unity 6.0+. Understands, edits, and generates UXML and USS files with flex-based layouts. Use for requests involving .uxml, .uss, UI Toolkit, UIElements, UIDocument, UI runtime binding, Custom UI Elements, Manipulators or PanelSettings.4---5
6Understand existing Unity UI Toolkit code, make targeted edits, generate new UXML/USS files, Manipulators, and handle UI runtime binding.
7
8## References
9
10Read these as needed:
11- `references/uss-guide.md` — USS patterns and examples
12- `references/svg-icons.md` — SVG icon generation (only when generating icons)
13- `references/common-issues.md` — Common mistakes to avoid
14- `references/ui-runtime-binding.md` — Patterns and guide to bind data to UI at runtime (only when requested or when bindings are involved)
15- `references/painter2d.md` — Painter2D API for custom visuals: gradients, shapes, arcs, procedural drawing (read this whenever gradients, custom shapes, progress rings, procedural drawing, or any visual beyond what USS can express is needed)
16- `references/pointermanipulator-guide.md` — Patterns and guide to create and use Manipulators (only when requested or when manipulators are involved). This helps with setting up drag and drop features or simple event handling for a Visual Element.
17- `references/custom-elements.md` — Custom UI Element patterns and guide to create reusable components with UXML, USS, and C#. This helps with creating complex UI components for reuse across the project.
18
19Paths are relative to this skill's folder — read `references/uss-guide.md` directly.
20
21## Understanding
22
23When explaining UI structure, use this format:
24```
25[ElementType] name="elementName" class="class1 class2"
26├── [ChildType] name="childName"
27│ └── [GrandchildType]
28└── [ChildType] class="another-class"
29```
30
31## Editing
32
33**Common edit requests:**
34
35| Request | Action |
36|---------|--------|
37| "Change button color" | Edit USS selector for that button |
38| "Add a label here" | Add element to UXML at specified location |
39| "Make this bigger" | Edit width/height in USS |
40| "Hide this element" | Add `display: none` to USS or remove from UXML |
41| "Rename this element" | Update `name` attribute in UXML |
42
43**Don't over-edit:**
44- Change only what's requested
45- Preserve formatting and structure
46- Don't "improve" unrelated code
47- Don't add comments unless asked
48- For targeted changes, prefer modifying specific elements or selectors over rewriting entire files — but use judgment; if a change touches most of the file, a rewrite may be cleaner
49- Be careful not to accidentally drop existing elements, styles, or references when making edits
50- **When editing USS**, focus on the properties and selectors relevant to the request — avoid unnecessary reorganization, but restructure if the change genuinely requires it
51
52## Validation
53
54There is no way to validate UXML or USS from outside the Editor — Unity parses these
55files on import and reports problems in the Console. Write the files, then have the
56user check the result.
57
58**Workflow:**
59
601. Write the complete file to its target path in the project. Do not write partial or
61 draft content — a half-written UXML file is a parse error the moment the Editor
62 picks it up.
632. Ask the user to focus the Unity Editor. That triggers a reimport of the changed
64 assets.
653. Ask them to report anything in the Console. UXML parse errors name the file and
66 line; USS problems appear as warnings about unknown properties or selectors.
674. Fix what they report and repeat from step 1.
68
69**Because feedback costs a user round-trip, get it right the first time:**
70
71- Finish all files before asking the user to check, so one reimport covers everything
72 rather than one per file.
73- Re-read `references/uss-guide.md` and `references/common-issues.md` before writing,
74 rather than after an error comes back.
75- Watch for the mistakes that survive a parse but render wrong — those will not appear
76 in the Console at all, so the user has to eyeball the UI. `references/common-issues.md`
77 lists them.
78
79## Generation
80
81When creating new UI:
82
83**Generate only what is requested:**
84
85| Request | Output |
86|---------|--------|
87| USS only | `.uss` file only |
88| UXML only | `.uxml` file only |
89| UI screen / menu / panel | `.uss` + `.uxml` only |
90| "with code" / "with logic" / "functional" | `.uss` + `.uxml` + `.cs` |
91
92**These do NOT imply C#:**
93- "proper buttons" → well-styled Button elements
94- "currency display" → a Label element
95- "working UI" → valid UXML/USS that renders
96- "inventory screen" → visual layout only
97- "inventory system" / "equipment system" / "crafting system" → Ask: "Should items be draggable?" If yes, see `references/pointermanipulator-guide.md` for patterns
98
99**Generation workflow:**
1001. **Analyze** — Determine exactly what files are needed. No extras.
1012. **Search** — Find existing USS, UXML, assets. Don't assume paths.
1023. **Follow project patterns** — Match folder structure and naming conventions.
1034. **Reuse** — Check for shared stylesheets. Reuse if appropriate.
1045. **Write USS first** — Verify against restrictions below.
1056. **Write UXML** — Reference the USS, verify structure.
1067. **Write the files out complete** — never partial content; see Validation above for
107 how errors come back and why one round of files beats several.
1088. **Scene setup** — Assign PanelSettings if adding UI to scene.
1099. **Data binding** — If requested, add C# script with runtime data binding patterns (see `references/ui-runtime-binding.md`). Generate the scriptable object asset if needed. Assign the asset to the UI element root in UXML or via datasource in C#.
110
111**Color, visibility, and specification rules:**
112- **Ensure text is readable by default:** When choosing colors, ensure text contrasts with its background — but respect intentional low-contrast uses (disabled states, placeholder text, decorative elements). When using design tokens, check that text and background variables provide adequate contrast.
113- **Honor exact values:** User-specified hex colors, pixel dimensions, spacing — use exactly as given. Do not approximate or substitute.
114
115**Styling / Theme**
116When styling UI or adjusting theme make sure to not only apply to the elements directly in the current UXML but also to the core elements of UI Toolkit which are composed of several child elements usually.
117
118## Conventions
119
120**Follow project patterns first.** Search existing files before applying defaults.
121
122| Type | Convention | Good | Bad |
123|------|------------|------|-----|
124| `name` attribute | camelCase | `submitButton` | `submit-button` |
125| `class` attribute / USS | kebab-case | `.submit-button` | `.submitButton` |
126| File paths | Feature folders | `Assets/UI/Inventory/` | `Assets/Scripts/UI/` |
127
128**Output format:**
129```uxml Filename.uxml
130<ui:UXML>...</ui:UXML>
131```
132```uss Filename.uss
133.class { ... }
134```
135
136## USS Restrictions
137
138Unity's USS is a subset of CSS. These properties do NOT exist — NEVER use them:
139
140| NEVER Use | Use Instead |
141|-----------|-------------|
142| `border` shorthand | `border-width`, `border-color` separately |
143| `gap` | `margin` on children |
144| `z-index` | DOM order or parent nesting |
145| `pointer-events` | `picking-mode` UXML attribute |
146| `filter` | Not supported |
147| `outline` | `border-*` properties |
148| `box-shadow` | Nested elements or background image |
149| `:first-child`, `:last-child`, `:nth-child` | Explicit classes |
150| `[attribute]` selectors | Explicit classes |
151| `transition-property: <value>` | Omit entirely, or `none`/`initial`/`inherit` only |
152| `linear-gradient()`, `radial-gradient()` | Custom `VisualElement` with Painter2D (see `references/painter2d.md`) |
153
154**Inline styles:** NEVER use `style="..."` in UXML. All styling in USS only.
155
156**External URLs:** NEVER use `url()` with external paths. Only `url("project://database/Assets/...")`.
157
158**Prefer flexible layouts over hardcoded sizes:**
159- Use `flex-grow`, `flex-shrink`, or `%` instead of fixed `width`/`height` values
160- Let elements flow naturally and be constrained by their parent container
161- Set explicit pixel sizes only on root containers or when a fixed size is truly required
162- Child elements should adapt to available space rather than define their own dimensions
163
164## USS Brevity
165
166- No default values (`flex-direction: column` is default)
167- No default fonts
168- No redundant constraints (`width: 100px` doesn't need `min-width`/`max-width`)
169- No overlapping properties (`flex: 1` already sets grow/shrink)
170- Simplest selector that works
171- Never duplicate selectors
172
173## UXML
174
175Every file must:
1761. Declare namespace: `<ui:UXML xmlns:ui="UnityEngine.UIElements">`
1772. Link stylesheet(s): `<ui:Style src="Screen.uss" />`
1783. Have exactly one top-level container
1794. **No `style="..."` attributes** — use USS only
180
181```uxml
182<ui:UXML xmlns:ui="UnityEngine.UIElements">
183 <ui:Style src="Panel.uss" />
184 <ui:VisualElement name="root" class="panel">
185 <!-- content -->
186 </ui:VisualElement>
187</ui:UXML>
188```
189
190## Events and Interactivity
191- Use Pointer Manipulators for event handling and interactivity on a VisualElement (see `references/pointermanipulator-guide.md`)
192- If drag and drop is requested then write a pointer Manipulator and attach it to the relevant Visual Element in UXML or via C#.
193- For simple click events, you can use the `clickable` manipulator in UXML
194- For more advanced interactions, create use more traditional event callbacks in C# and attach them to elements as needed
195
196**For inventory and crafting systems:**
197- When users request an "inventory system", "equipment system", or "crafting system", ask explicitly: "Should players be able to drag and drop items?"
198- If yes, read `references/pointermanipulator-guide.md` for inventory/crafting-specific patterns
199- If no or unclear, create static layout only
200
201## Assets
202
203**Do NOT reference `UnityDefaultRuntimeTheme.tss`** or Unity's built-in theme icons.
204
205**Icon priority:**
2061. Reuse existing project icons
2072. Generate SVG (see `references/svg-icons.md`)
2083. Image generators (last resort)
209
210**Reference format:**
211```uss
212background-image: url("project://database/Assets/UI/Textures/icon.png");
213```
214
215## Scene Setup
216
217**PanelSettings is required** — UI won't render without it.
218
2191. Search for existing PanelSettings asset
2202. If none, create generic: `Assets/UI/PanelSettings.asset`
2213. Assign to UIDocument's `Panel Settings` field
222
223Skip for Editor UI (EditorWindow, PropertyDrawer).
224
225## C# (Only When Requested)
226
227- Style via USS classes (`AddToClassList()`) — never use `element.style.*` as inline styles have higher specificity than USS selectors, making them impossible to override via stylesheets, and add per-element memory overhead
228- UITK uses TextCore text assets — use `FontAsset`, `TextStyleSheet`, and `TextSettings`, not their TextMeshPro equivalents (`TMP_FontAsset`, etc.)
229- Place scripts in same folder as UXML/USS