ドキュメント

Unity Engine

Download Unity

Unity Engine

Work with elements in-scene

Add, reorder, and manage visual elements in the scene.
読み終わるまでの所要時間 4 分最終更新 9日前

The basic building block in UI Toolkit is a
VisualElement
. Visual elements form a parent-child visual tree. You can add and organize elements directly in the Hierarchy window in the Main Stage, or in UI Staging mode.

Add elements

To add an element to a UXML document:
  1. Open the element menu using one of the following methods:
    • In the Hierarchy window or in UI Staging mode, select + > UI Toolkit > Standard Element.
    • In the main menu, go to
      GameObject

      ?

      > UI Toolkit > Standard Element.
  2. Select the element from the list.
    If the element you want isn't in the list, select UI Library to open the UI Library window, then select the element or drag it directly from the UI Library window to the UXML document.
After you add an element, the Hierarchy window expands to show the new element, selects it, and starts renaming it so you can give it a name. Template instances are selected but not renamed.
注
When you add an element from the UI Library window in the Main Stage, Unity adds it to the UXML document of the selected element or of the selected GameObject's Panel Renderer component. If that Panel Renderer has no source asset, Unity creates a UXML asset and assigns it to the component. If nothing selected has a Panel Renderer, Unity creates a GameObject with a Panel Renderer component and a new UXML asset that contains the element.

Add a child element

To add a child element to a parent:
  1. Right-click (macOS: Ctrl+click) the parent and select Standard Element > Add Child.
  2. Select the element from the list.
By default, elements have no Name attribute and appear in the Hierarchy window by type. To name an element, right-click it in the Hierarchy window and select Rename, or set a name in the
Inspector

?

window. Names identify elements in the UI and don't need to be unique. However, an element must have a name before you can override its attributes in a template instance.

Reorder elements

To reorder elements, you can drag one or more elements in the hierarchy or move them between parents:

Reorder in hierarchy

Move elements between UI documents

In the Main Stage, you can drag an element from one UI document to another in the Hierarchy window.

Move world space elements in the Scene view

You can use the Move, Rotate, and Scale tools to transform elements in the
Scene

?

view. Unity writes the result as inline styles on the element's
translate
,
rotate
, and
scale
properties. In the Main Stage, these tools are available for world space UI only.
When you select a visual element that these tools can transform, the Tools overlay in the Scene view switches to the visual element context and shows the tools available for that element.

Locate and frame elements

To find a UI element in the view, select it in the Hierarchy window and do one of the following:
  • Double-click the element.
  • Press F, or select Edit > Frame Selected.
  • Right-click (macOS: Ctrl+click) the element and select Frame Selection. The context menu shows each action's shortcut.
For world-space UI, you can also press Option+F (macOS) or Alt+F (Windows), or right-click the element and select Frame and Align to View, to frame the panel so the camera faces it head-on.
When you edit in UI Staging, framing an element resolves its world-space instance in the scene automatically.

Use the context menu in the Scene view

To choose from all elements under the pointer, hold Ctrl (macOS: Cmd) and right-click in the Scene view.

Save and rename UXML assets

To save one UXML asset without saving other modified assets, do one of the following:
  • In the Hierarchy window, right-click the UXML document and select Save <file_name>.
  • In the Inspector window, open the More (⋮) menu and select Save <file_name>.
To rename a UXML asset, rename its
.uxml
node in the Hierarchy window. This renames the
.uxml
file in your project. The GameObject keeps its name.

Edit text in the UI Viewport

For text elements such as Button or Label, you can edit the
text
attribute in the UI Viewport window by double-clicking the control. Press Enter to add a new line. Press Shift + Enter to commit. Press Esc to cancel.

Additional resources