Version: Unity 6.7 Beta (6000.7)
Language : English
Reference runtime visual elements in Inspector
World Space UI

Use UXML instances as templates in-scene

You can instantiate existing UXML documents as templates inside another UXML document, similar to PrefabsAn asset type that allows you to store a GameObject complete with components and properties. The prefab acts as a template from which you can create new object instances in the scene. More info
See in Glossary
. In the Hierarchy window, a template appears as a template instance of type TemplateContainer.

Use a UXML document as a template

To instantiate an existing UXML document:

  1. In the Project or the UI Library window, find the .uxml asset.
  2. While in UI Staging mode, drag it into the Hierarchy or the UI Viewport window.

A Template Instance appears in the Hierarchy window. Unity shows the source file name in grey beside the instance name. Expand the instance to view its internal hierarchy for reference. The internal hierarchy is read-only in the parent document.

Create a template from an element

To save an existing element and its children as a new UXML template:

  1. In the Hierarchy window, right-click (macOS: Ctrl+click) the element.
  2. Select Create Template.
  3. Choose a name and location for the new .uxml file.

Unity exports the element and its children to the new file and replaces the original element with a Template Instance that references it. This action isn’t fully reversible: Undo restores the element in the hierarchy but doesn’t delete the created .uxml file.

Unpack a template instance

Unpacking replaces a Template Instance with the child elements from the template placed directly in the parent document. Unity preserves inline attributes and child attribute overrides.

To unpack a template instance:

  1. In the Hierarchy window, right-click (macOS: Ctrl+click) the template instance.
  2. Select one of the following:
  3. Unpack Template: Expand the outermost template instance one level.
  4. Unpack Template Completely: Recursively expand all nested template instances.

Edit a template instance

To edit the UXML used by a template instance, right-click (macOS: Ctrl+click) the instance in the Hierarchy window and select one of the following:

  • Open Instance in UI Builder > In Isolation: Load only the template. Parent document style sheets appear read-only in the Style Sheets window because they still apply to the instance.
  • Open Instance > In Isolation: Load only the template and stay in UI Staging mode. Parent document style sheets appear read-only in the Style Sheets window.
  • Open Instance in UI Builder > In Context: Keep the parent document visible (read-only) and edit the template in place.
  • Open Instance > In Context: Edit the template in UI Staging mode while keeping parent context.

When you edit in context or isolation, a breadcrumb bar appears in the UI Viewport window. Use it to navigate back to parent documents.

You can also open a template from the Inspector window header when you select a Template Instance.

Additional resources

Reference runtime visual elements in Inspector
World Space UI