Version: Unity 6.5 Alpha (6000.5)
LanguageEnglish
  • C#

VisualTreeAsset.CloneTree

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public UIElements.TemplateContainer CloneTree();

Returns

UIElements.TemplateContainer The root of the tree of VisualElements that was just cloned.

Description

Build a tree of VisualElements from the asset.


Declaration

public UIElements.TemplateContainer CloneTree(String bindingPath);

Parameters

Parameter Description
bindingPath The path to the property that you want to bind to the root of the cloned tree.

Returns

UIElements.TemplateContainer The root of the tree of VisualElements that was just cloned.

Description

Build a tree of VisualElements from the asset.


Declaration

public Void CloneTree(UnityEngine.UIElements.VisualElement target);

Parameters

Parameter Description
target A VisualElement that will act as the root of the cloned tree.

Description

Builds a tree of VisualElements from the asset.


Declaration

public Void CloneTree(UnityEngine.UIElements.VisualElement target, out UnityEngine.UIElements.VisualElementAssetReferenceTable referenceTable);

Parameters

Parameter Description
referenceTable A table to use to resolve references.

Description

Builds a tree of VisualElements from the asset and fills a VisualElementAssetReferenceTable.

This example shows how to use the <see cref="VisualElementAssetReferenceTable" /> to resolve references to VisualElements after calling CloneTree.

using UnityEngine;
using UnityEngine.UIElements;

public class VisualElementAssetReferenceTable_CloneTreeExample : MonoBehaviour { // Set via the Inspector public VisualTreeAsset treeAsset;

void Start() { var target = new VisualElement(); treeAsset.CloneTree(target, out var referenceTable);

// Example of retrieving a referenced element by its Authoring Id if (referenceTable.TryGetReference<Button>(new AuthoringIdPath(42), out var myButton)) { Debug.Log("Found button!"); }

// Example of retrieving a the root element if (referenceTable.TryGetReference<VisualElement>(new AuthoringIdPath(0), out var root)) { Debug.Log("Found root!"); }

// Example of retrieving a nested element inside of multiple template instances if (referenceTable.TryGetReference<VisualElement>(new AuthoringIdPath(1, 5, -19, 11, 1), out var nestedElement)) { Debug.Log("Found nested element!"); }

// Release the reference table back to the pool when done referenceTable.ReleaseToPool(); } }