> For the complete documentation index, see [llms.txt](https://renownedgames.gitbook.io/ai-tree/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://renownedgames.gitbook.io/ai-tree/basic/user-guide.md).

# User Guide

This section illustrates how to create the various [**Behavior Tree**](/ai-tree/basic/behaviour-tree.md) assets within Unity.

Behavior Trees are essentially the Is processor and can make decisions and execute various branches based on the outcome of those decisions. Now an example of creating a simple bot will be shown:

### Creating Behavior Tree

Behavior Trees are essentially the AI's processor and can make decisions and execute various branches based on the outcome of those decisions.

Click on the **Assets** tab, then select **Create/Renowned Games/Behavior Tree**

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2F5wlIA5hLKOd4XPvVfTp3%2Ffotor_2023-1-19_15_12_8.png?alt=media&amp;token=292a6189-1624-4dd6-9f0d-8a4258ca2252" alt=""><figcaption><p>Creating Behavior Tree</p></figcaption></figure>

{% hint style="info" %}
Also you can right-click in the **Project** **Window**, then select **Create/Renowned Games/Behavior Tree**
{% endhint %}

The new **Behavior Tree** asset will be added to the **Project Window** which you can rename to your desired name.

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2FehsHNlhL25XTjEmaYjFW%2Fimage.png?alt=media&amp;token=b1eccdcc-65d9-491c-874c-3dc5e0a4f13c" alt=""><figcaption><p>Behavior Tree Name</p></figcaption></figure>

### Creating Random Position Task

To create [**Random Position**](/ai-tree/nodes/tasks/navmesh/random-position.md) node, we need to go to the desired **Behavior tree** and right-click the context menu.

Click on **Create Node/Tasks/NavMesh/Random Position**

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2FBJ2vu6lD109kxt6qJEjp%2Ffotor_2023-1-19_15_26_1.png?alt=media&amp;token=d07cfa03-9850-424b-abff-642ac086a275" alt=""><figcaption></figcaption></figure>

To save the position value we need to create [**Blackboard**](/ai-tree/basic/blackboard.md)**.**

### **Creating Blackboard**

Click on the **Assets** tab, then select **Create/Renowned Games/Blackboard**

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2FMnRKi7pydR5aR508vyD0%2Ffotor_2023-1-18_17_38_2.png?alt=media&amp;token=0b2b6528-13ef-4f68-8556-c8b1d78c74ed" alt=""><figcaption><p>Creating Blackboard</p></figcaption></figure>

{% hint style="info" %}
Also you can right-click in the **Project** **Window**, then select **Create/Renowned Games/Blackboard**
{% endhint %}

The new **Blackboard** asset will be added to the **Project Window** which you can rename to your desired name.

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2FDAYKzFkgWmeg4oTSxdfV%2Fimage.png?alt=media&amp;token=72c3cbb5-5dc1-4aca-b6b5-29b803f29e22" alt=""><figcaption><p>Blackboard name</p></figcaption></figure>

### Connecting Blackboard in Behavior Tree

To connect **Blackboard** to the **Behavior Tree**, click on the **Behavior Tree** we need and drag the desired **Blackboard** into the **Behavior Tree** inspector window where the **Blackboard** field will be.

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2FBJzfmLp3ISqhyY4CK0z7%2Ffotor_2023-1-18_17_51_43.png?alt=media&amp;token=bc89211e-ef88-4b68-a6d5-9e91e95b5bb6" alt=""><figcaption><p>Behavior Tree Inspector</p></figcaption></figure>

{% hint style="info" %}
You can also add it by clicking on the field with blackboard and select it from all the blackboards in the project.
{% endhint %}

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2FRvNFL3fo6VX5BaDChl7q%2Ffotor_2023-1-19_15_7_33.png?alt=media&amp;token=49e2a816-69f6-4ebe-9527-01ecb899d7d3" alt=""><figcaption><p>Connecting Blackboard in Behavior Tree</p></figcaption></figure>

### Creating Keys for Blackboard

In the **Blackboard**, we create a **Key** with the vector type and call it *position*.

To create a **Key**, click on the **New Key** tab.

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2FDr764RA9kYt3L3tIB5T4%2Ffotor_2023-1-18_18_22_6.png?alt=media&amp;token=ea9fd295-e9ca-4783-a2ae-e67fd68edcdc" alt=""><figcaption><p>Creating new Key</p></figcaption></figure>

In the window that opens, select the **Key** type.

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2FIsGKLeAnUMMj5nd3L0kT%2Fimage.png?alt=media&amp;token=10ed2b44-b087-4d76-8360-286b9c36eb9e" alt=""><figcaption><p>Selecting Key types</p></figcaption></figure>

An example of how it should turn out:

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2FJ1Q9okVtmbxN2UWQWvCN%2Fimage.png?alt=media&amp;token=ce613bf6-0eeb-47aa-ab46-bfb48aa9a4b1" alt=""><figcaption><p>Creating position Key </p></figcaption></figure>

In the **Random Position** node inspector window, specify your new **Key.**

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2FHrBYAkbyMMGRqXyijeFw%2Fimage.png?alt=media&amp;token=89d21505-572b-42a5-9d4c-6dbe9823d557" alt=""><figcaption><p>Assigning new Key in Task</p></figcaption></figure>

### Creating Move To Task

So that our character can approach the generated position, we will create [**Move To**](/ai-tree/nodes/tasks/navmesh/move-to.md) node.

To create **Move To** node, we need to go to the desired **Behavior tree** and right-click the context menu.

Click on **Create Node/Tasks/NavMesh/Move To**

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2FbyuB10PqBLG1IziTpbt2%2Ffotor_2023-1-20_2_14_18.png?alt=media&amp;token=64da696a-e57b-49ad-96e4-18bc0eb29db5" alt=""><figcaption><p>Creating Move To Task</p></figcaption></figure>

In the **Move To** node inspector window, specify *position* **Key.**

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2FNd9PS17ayJz3HPURYugs%2Ffotor_2023-1-20_2_17_2.png?alt=media&amp;token=25daf398-fe7d-42f6-8064-9425bb1f0f51" alt=""><figcaption><p>Assigning new Key in Task</p></figcaption></figure>

### Creating Wait Task

To create a small delay, we will create [**Wait**](/ai-tree/nodes/tasks/common/wait.md) node.

To create **Wait**, we need to go to the desired **Behavior tree** and right-click the context menu.

Click on **Create Node/Tasks/Common/Wait**

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2Fq9TkC5nWq2gSdRrrr3G5%2Ffotor_2023-1-20_2_21_47.png?alt=media&amp;token=f3a37088-b468-47b6-9761-bea34bdb82ed" alt=""><figcaption><p>Creating Wait Task</p></figcaption></figure>

As in **Move To Task**, we add the *position* **Key**

In field Wait time specify 3 seconds.

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2FicMpMvJkXzWSDGEcvUbP%2Ffotor_2023-1-20_2_32_8.png?alt=media&amp;token=ebc92b4b-f588-47fd-8140-6256f92e7400" alt=""><figcaption><p>Filling Wait Time field</p></figcaption></figure>

{% hint style="info" %}
If you don't want to create a **Key** in the **Blackboard**, then you can click on the flag next to the field and enter your fixed value.
{% endhint %}

### Creating Sequencer

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2FEuXIe51XciBLxSP9Fmm5%2Fimage.png?alt=media&amp;token=4e2b8987-2dd4-45b6-ab5f-aec358e250f5" alt=""><figcaption><p>Now our tree looks like this.</p></figcaption></figure>

To link our years we need to add [Sequencer](/ai-tree/nodes/composite/sequencer.md). Executes child nodes alternately.

To create **Sequencer**, we need to go to the desired **Behavior tree** and right-click the context menu.

Click on **Create Node/Tasks/Composites/Sequencer**

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2FhnZ6oYWnciYDI9C2b9ux%2Ffotor_2023-1-20_2_45_51.png?alt=media&amp;token=6d747998-436f-4a47-b40e-e7d52ef6b68a" alt=""><figcaption><p>Creating Sequencer</p></figcaption></figure>

### Linking Nodes

To link a node, you must pull the connection from the top or bottom of the node (indicated by a circle) to the center of another node.

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2FuDtb9yp3HUvGfGmExTsw%2Ffotor_2023-1-20_2_51_43.png?alt=media&amp;token=9b0226bb-da6a-4300-9a0a-46cc07287679" alt=""><figcaption><p>Link example</p></figcaption></figure>

{% hint style="info" %}
Connecting nodes in **Behavior Trees** only work by connecting an output to an input (you cannot connect from an input to an output).
{% endhint %}

We connect the remaining nodes in the same way:

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2FX2m0NY0Cfje6ESWc5Gih%2Fimage.png?alt=media&amp;token=d184609b-14d3-445c-8c00-18ccf384d3ff" alt=""><figcaption><p>Links example</p></figcaption></figure>

### Connecting Behavior Tree with GameObject

To connect **Behavior Tree** to GameObject, we need to add a component to it Behavior Runner.

To do this, go to the inspector window of the necessary GameObject.

Clicks Add Component and searches Behavior Runner.

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2FCOxH21cf2JlBrjSTJ83d%2Ffotor_2023-1-20_3_6_18.png?alt=media&amp;token=32044f78-286f-4b5c-a6f5-423d81299204" alt=""><figcaption></figcaption></figure>

In the Behavior Runner field, connect our created **Behavior Tree.**

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2FSemY3BOnOIC7BuSHI2yV%2Ffotor_2023-1-20_3_7_42.png?alt=media&amp;token=2ac0ac90-5350-4516-9cf5-6e8aebdc2f02" alt=""><figcaption></figcaption></figure>
