> For the complete documentation index, see [llms.txt](https://sniveler-code.gitbook.io/dots/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sniveler-code.gitbook.io/dots/project-ai-behavior-architect/section-3/working-with-sub-trees.md).

# 🗂 Working with Sub-Trees

As your AI logic grows, your graphs can become massive. **Sub-Trees** allow you to encapsulate logic into smaller, reusable Graph Assets. For example, you can build an Attack Sub-Tree and reuse it across multiple different enemy types.

#### 🏗 How to Setup a Sub-Tree

1. Create a new `GraphAsset` in your project folder (e.g., `Sub_MeleeAttack`).
2. Open your main behavior tree in the Behavior Editor.
3. Add a **Composites > Sub-Tree** node.
4. Select the `Sub-Tree` node. In the left-hand **Node Tab**, assign your `Sub_MeleeAttack` asset to the field.

#### 🧭 Navigating Sub-Trees

* **Diving In:** Simply **double-click** the Sub-Tree node on the canvas, or click the "Open Sub-Tree" button in the Node Tab. The editor will instantly load the nested graph.
* **Going Back:** Look at the top toolbar. You will see a breadcrumb trail showing your current depth. Click the name of the parent tree to return.

> ⚠️ **Circular Dependency Protection**\
> The compiler strictly prevents infinite loops. You cannot assign a Graph Asset to itself, nor can you place a Sub-Tree inside a graph that eventually calls the parent graph. The compiler will catch this and throw a helpful error in the console.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://sniveler-code.gitbook.io/dots/project-ai-behavior-architect/section-3/working-with-sub-trees.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
