# Binding

{% stepper %}
{% step %}
To set up linking by Guid, open your UXML layout, go to the Library section, and click on the Project tab.

In the list of elements, find the "UitkElementLinker" asset elements, and drag the necessary element with the "G" prefix into your layout.
{% endstep %}

{% step %}
Click on the added element to open its inspector.

In the inspector, you will see the standard fields of the element from which the G-element is inherited (in this case, a button), as well as a new field "Guid".

The value in the Guid field should be in "override" state, meaning it should have a white stripe next to the field.\
If there is no white stripe, it means that upon reopening the UXML file, the guid in the field will change to a random one, and the linking will stop working.

To switch the field to "override" state, you can manually add any character to the current field value and then remove it.

After this, be sure to save your UXML file.
{% endstep %}

{% step %}
After you have set up the Guid, create an empty GameObject on the scene and add a component that will facilitate the linking between your UITK element and the MonoBehaviour script.

The name of the linking script is formed as follows:\
"Uitk" + ElementName.

In our case, the script is called "UitkButton".
{% endstep %}

{% step %}

###

If you don’t have a UIDocument component, create an empty GameObject on the scene, add the UIDocument component to it, serialize your UXML file in it, as well as the PanelSettings file.\
You can learn more about PanelSettings [here](https://blog.unity.com/engine-platform/ui-toolkit-at-runtime-get-the-breakdown).
{% endstep %}

{% step %}

###

Drag the GameObject, to which the UIDocument script has been added, into the "Ui Document" field of the UitkButton script.
{% endstep %}

{% step %}

###

Switch the "Linking Mode" parameter to the "Guid" state.
{% endstep %}

{% step %}

###

Now you can choose one of two possible methods to link the element via GUID.

1. Using the "Guid" field, linking with a single guid. In this case, the element search will be conducted throughout the hierarchy of your layout.

This method is not very efficient, especially for large and complex layouts, but it is convenient if the upper hierarchy of your element often changes during development.

When searching for an element using the "guid" field, the parents of the sought element can be both G-elements and regular elements from the UnityEngine.UIElements namespace.

2. Using the "Guids" field, linking with a hierarchy of the element. That is, the GUIDs of all the parents of your element will be used to search for the element. In this case, the element search will only be conducted along one branch of the hierarchy, ignoring other parts of the hierarchy where your element is not present.

This is the most efficient way to find a element, but at the same time, if you change the parent of your element, or any other parent in the upper hierarchy of your element - you will need to update the "Guids" field for your element, otherwise it will not be found.

As a suggestion, use linking via the "Guid" field during development/prototyping, and switch to "Guids" before release when you will no longer be making changes to your layout, to improve the performance of your game/app. In such a case, all the elements of the hierarchy branch where your element is located must be G-elements.
{% endstep %}

{% step %}

###

To link your element using the "Guid" field, following the first method, insert the guid of your element into the "Guid" field.
{% endstep %}

{% step %}

###

To link your element through the "Guids" field, following the second method: 

1. Open your UXML layout
2. Select your element by clicking it once with the left mouse button
3. In the context menu at the top of the Unity window (not in the UI Builder window), click on\
   "Tools > Assets > Copy element guid hierarchy" item.
4. If the hierarchy was copied successfully, you will see a message in the console:
5. If you see an error when trying to copy a hierarchy, please notify the asset developer.
6. Now you have configured element linking using the "Guids" field.
   {% endstep %}
   {% endstepper %}
