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
- Type: Class
- Namespace: UnityEngine.UIElements
- Assembly: UnityEngine.UIElementsModule
- Inherits from: ScriptableObject
[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 |
|---|---|
| contentHash | A hash value computed from the template content. |
| importedWithErrors | Whether there were errors encountered while importing the UXML File |
| importedWithWarnings | Whether there were warnings encountered while importing the UXML File |
| stylesheets | The stylesheets used by this VisualTreeAsset. |
| templateDependencies | The UXML templates used by this VisualTreeAsset. |
Methods
Method | Description |
|---|---|
| CloneTree | Build a tree of VisualElements from the asset. |
| Instantiate | Build a tree of VisualElements from the asset. |
Inheritance
Operators
Operator | Description |
|---|---|
| operator == | Compares two object references to see if they refer to the same object. |
| bool | Determines whether the object exists. |
| operator != | Compares if two objects refer to a different object. |