Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


VisualTreeAsset

An instance of this class holds a tree of VisualElementAsset's, created from a UXML file. Each node in the file corresponds to a VisualElementAsset. You can clone a VisualTreeAsset to create a tree of VisualElement's. Note: You can't generate a VisualTreeAsset from raw UXML at runtime.
Read time 5 minutesLast updated 3 days ago

Definition

[HelpURL("UIE-VisualTree-landing")]public class VisualTreeAsset : ScriptableObject

Remarks

The following example loads a VisualTreeAsset from a UXML file in a custom Editor script.

Examples

using UnityEditor;using UnityEngine;using UnityEngine.UIElements;public class VisualTreeAssetExample : EditorWindow{ [MenuItem("Window/VisualTreeAssetExample")] public static void ShowWindow() { var window = GetWindow<VisualTreeAssetExample>(); window.titleContent = new GUIContent("VisualTreeAssetExample"); } public void CreateGUI() { // Load the UXML asset var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Editor/MyCustomEditor.uxml"); if (visualTree != null) { // Clone the UXML and add it to the root VisualElement VisualElement root = visualTree.CloneTree(); rootVisualElement.Add(root); } else { Debug.LogError("UXML file not found at specified path."); } }}

Properties

Property

Description

contentHashA hash value computed from the template content.
importedWithErrorsWhether there were errors encountered while importing the UXML File
importedWithWarningsWhether there were warnings encountered while importing the UXML File
stylesheetsThe stylesheets used by this VisualTreeAsset.
templateDependenciesThe UXML templates used by this VisualTreeAsset.

Methods

Method

Description

CloneTreeBuild a tree of VisualElements from the asset.
InstantiateBuild a tree of VisualElements from the asset.

Inheritance

Inherited Members

Operators

Operator

Description

operator ==Compares two object references to see if they refer to the same object.
boolDetermines whether the object exists.
operator !=Compares if two objects refer to a different object.