# CloneTree

> Build a tree of VisualElements from the asset.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine.UIElements](/engine/6000.5/script-reference/unityengine/uielements.md)
* **Assembly:** UnityEngine.UIElementsModule

## CloneTree()

Build a tree of VisualElements from the asset.

```csharp
public TemplateContainer CloneTree()
```

### Returns

| Type                                                                                             | Description                                                  |
| ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------ |
| [TemplateContainer](/engine/6000.5/script-reference/unityengine/uielements/templatecontainer.md) | The root of the tree of VisualElements that was just cloned. |

## CloneTree(string)

Build a tree of VisualElements from the asset.

```csharp
public TemplateContainer CloneTree(string bindingPath)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The path to the property that you want to bind to the root of the cloned tree.

### Returns

| Type                                                                                             | Description                                                  |
| ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------ |
| [TemplateContainer](/engine/6000.5/script-reference/unityengine/uielements/templatecontainer.md) | The root of the tree of VisualElements that was just cloned. |

## CloneTree(VisualElement)

Builds a tree of VisualElements from the asset.

```csharp
public void CloneTree(VisualElement target)
```

### Parameters

**** (\[VisualElement]\(/engine/6000.5/script-reference/unityengine/uielements/visualelement)): A VisualElement that will act as the root of the cloned tree.

## CloneTree(VisualElement, VisualElementAssetReferenceTable)

Builds a tree of VisualElements from the asset and fills a [VisualElementAssetReferenceTable](/engine/6000.5/script-reference/unityengine/uielements/visualelementassetreferencetable.md).

```csharp
public void CloneTree(VisualElement target, out VisualElementAssetReferenceTable referenceTable)
```

### Parameters

**** (\[VisualElement]\(/engine/6000.5/script-reference/unityengine/uielements/visualelement)): **** (\[VisualElementAssetReferenceTable]\(/engine/6000.5/script-reference/unityengine/uielements/visualelementassetreferencetable)): A table to use to resolve references.

### Remarks

This example shows how to use the `VisualElementAssetReferenceTable` to resolve references to VisualElements after calling CloneTree.

### Examples

```csharp
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();
    }
}
```

## CloneTree(VisualElement, int, int)

Build a tree of VisualElements from the asset.

```csharp
public void CloneTree(VisualElement target, out int firstElementIndex, out int elementAddedCount)
```

### Parameters

**** (\[VisualElement]\(/engine/6000.5/script-reference/unityengine/uielements/visualelement)): **** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): **** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)):&#x20;
