{"id":14960763,"url":"https://github.com/moshitinencoded/ai-behaviour-tree","last_synced_at":"2025-10-24T19:30:25.107Z","repository":{"id":220879642,"uuid":"689450572","full_name":"MoshitinEncoded/AI-Behaviour-Tree","owner":"MoshitinEncoded","description":"A visual, node-based Behaviour Tree tool for Unity.","archived":false,"fork":false,"pushed_at":"2024-06-05T00:29:47.000Z","size":631,"stargazers_count":4,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-22T11:31:14.671Z","etag":null,"topics":["ai","behavior-tree","behaviour-trees","graph","unity","unity-editor","unity-package","unity-scripts"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MoshitinEncoded.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-09T21:04:50.000Z","updated_at":"2024-05-17T05:55:59.000Z","dependencies_parsed_at":"2024-03-14T07:42:49.665Z","dependency_job_id":"d615ae4f-a19c-4d50-b7d5-74cd2632f149","html_url":"https://github.com/MoshitinEncoded/AI-Behaviour-Tree","commit_stats":{"total_commits":59,"total_committers":2,"mean_commits":29.5,"dds":"0.11864406779661019","last_synced_commit":"3f44f4eecdc5796b137c38d40ed769a4f95febe4"},"previous_names":["moshitinencoded/ai-behaviour-tree"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MoshitinEncoded%2FAI-Behaviour-Tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MoshitinEncoded%2FAI-Behaviour-Tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MoshitinEncoded%2FAI-Behaviour-Tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MoshitinEncoded%2FAI-Behaviour-Tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MoshitinEncoded","download_url":"https://codeload.github.com/MoshitinEncoded/AI-Behaviour-Tree/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219867815,"owners_count":16554365,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","behavior-tree","behaviour-trees","graph","unity","unity-editor","unity-package","unity-scripts"],"created_at":"2024-09-24T13:22:55.882Z","updated_at":"2025-10-24T19:30:24.368Z","avatar_url":"https://github.com/MoshitinEncoded.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Portrait](Documentation~/Images/AIBehaviourTree_Portrait.JPG)\n# AI Behaviour Tree\n\nBehaviour Trees are an amazing way of creating AIs, letting you write complex behaviours in a modular, easy and intuitive way. This project tries to deliver a simple yet complete Behaviour Tree tool for Unity with Editor and Runtime features.\n\nThis README assumes that you have some idea of what a BehaviorTree is; If you don't, I suggest you Google it first.\n\n\u003e [!NOTE]\n\u003e The minimum version currently supported is **Unity 2022.2**\n\n\u003e [!WARNING]\n\u003e This project is in an early phase of development and although it is quite stable, you may encounter bugs and is **NOT** recommended for use in production.\n\n## Table of Contents\n\n1. [Features](#features)\n2. [Installation](#installation)\n3. [Getting Started](#getting-started)\n    1. [Graph](#graph)\n        - [Navigation](#navigation)\n        - [Shortcuts](#shortcuts)\n        - [Create Nodes](#create-nodes)\n        - [Create Custom Nodes](#create-custom-nodes)\n            - [Node Classes](#node-classes)\n            - [CreateNodeMenu Attribute](#createnodemenu-attribute)\n            - [Node Functions](#node-functions)\n    2. [Blackboard](#blackboard)\n        - [Add Parameters](#add-parameters)\n        - [Get/Set Parameter Values](#getset-parameter-values)\n            - [By BehaviourTreeRunner Functions](#by-behaviourtreerunner-functions)\n            - [By Parameter Reference](#by-parameter-reference)\n        - [Create Custom Parameters](#create-custom-parameters)\n            - [AddParameterMenu Attribute](#addparametermenu-attribute)\n    3. [BehaviourTreeRunner](#behaviourtreerunner)\n        - [Inspector](#inspector)\n        - [Main Functions](#main-functions)\n4. [Attributions](#attributions)\n\n## Features\n\n- Graph Node Editor\n- Blackboard Editor\n- Blackboard Overrides\n- Runtime Debugger\n\n## Installation\n\n\u003e [!NOTE]\n\u003e At the moment, you can install this package ONLY through the **Package Manager** using **Git**.\n\nFirst of all, we need to install a dependency called **METools**.\n\nOpen your Unity project, go to `Window \u003e Package Manager` and click the `+` dropdown on the **top-left** corner, then select `Add package from git URL...` and paste the following URL:\n\n```\nhttps://github.com/MoshitinEncoded/METools.git\n```\n\n\u003e [!NOTE]\n\u003e If you receive the error `No 'git' executable was found` you're likely missing a **git** installation. You can install **git** from here: https://git-scm.com/download/win\n\nOnce installed, do the same with this package:\n\n```\nhttps://github.com/MoshitinEncoded/AI-Behaviour-Tree.git\n```\n\n## Getting Started\n\nAI Behavior Tree is mainly composed of a **ScriptableObject** called `BehaviourTree` and a **MonoBehaviour** called `BehaviourTreeRunner`.\n\nLike Unity's `Animator`, the **ScriptableObject** contains the behavior while the **MonoBehaviour** is responsible for running it. Let's start by creating a `BehaviourTree` in our project.\n\n1. Go to your project window and right-click to open the context menu or click the `+` button in the top left corner.\n2. Select `Create \u003e Moshitin Encoded \u003e Behaviour Tree` and choose a name.\n3. Double click on the **ScriptableObject** to edit it.\n\nYou will see that a new window has appeared, arrange it to your liking and let's see what it has:\n\n![Initial Graph](Documentation~/Images/AIBehaviourTree_InitialGraph.JPG)\n\n*A blank BehaviourTree graph.*\n\nAs you can see it is super simple, on one hand we have the **Graph** and on the other the **Blackboard**.\n\n### Graph\n\nThe Graph contains the tree of nodes and their connections. At first you will only have one default node called `Root`, which cannot be copied or deleted.\n\nIn each frame the tree begins its execution through the `Root` and then continues towards its child. When the child returns its state to the `Root`, it terminates the execution of the tree in that frame.\n\nThere are only 3 states that a node can return: `Success`, `Running` or `Failure`.\n\n\u003e [!IMPORTANT]\n\u003e Note that if the `Root` receives the status `Success` or `Failure`, it will stop the tree from running completely and you will need to restart it manually.\n\n#### Navigation\n\n| Action               | Control             |\n| -------------------- | ------------------- |\n| Pan                  | Middle-Click + Drag |\n| Zoom                 | Mouse wheel scroll  |\n| Select               | Left-Click          |\n| Rect Select          | Left-Click + Drag   |\n| Drag Selection       | Left-Click + Drag (over node)|\n| Add/Remove Selection | Ctrl + Left-Click   |\n| Open Contextual Menu | Right-Click         |\n\n#### Shortcuts\n\n| Action               | Shortcut            |\n| -------------------- | ------------------- |\n| Delete               | Del                 |\n| Copy                 | Ctrl + C            |\n| Paste                | Ctrl + V            |\n| Duplicate            | Ctrl + D            |\n| Focus Selection      | F                   |\n| Focus All            | A                   |\n| Create Node          | Spacebar            |\n\n#### Create Nodes\n\nRight click on the Graph and select `Create Node` or press the `Space` key on your keyboard to open the search window. Here you can search for any type of node that comes by default or that you have created yourself. Selecting any of these will add it to the graph of your BehaviourTree.\n\n#### Create Custom Nodes\n\nCreating your own node is very simple, you just have to create a script that inherits from a **node class** and add the `CreateNodeMenu` attribute on top of it.\n\n##### Node Classes\n\nAt the moment there are 3 node classes you can inherit from:\n\n| Node Class      | Description                                             |\n| --------------- | ------------------------------------------------------- |\n| `CompositeNode` | Has multiple childs. It is meant for flow control.      |\n| `DecoratorNode` | Has only one child. It is meant for child/flow control. |\n| `TaskNode`      | Does not have children. It is meant for logic.          |\n\n\u003e [!NOTE]\n\u003e If the compiler doesn't find the node classes, make sure you import these `namespaces` at the start of your script:\n\u003e ```CSharp\n\u003e using MoshitinEncoded.AI;\n\u003e using MoshitinEncoded.AI.BehaviourTreeLib;\n\u003e ```\n\n##### CreateNodeMenu Attribute\n\nOnce you have created your class, you may notice that the `CreateNodeMenu` attribute requires a `path`. This parameter represents the submenu in the search window where your node will appear (e.g. \"Task/Follow Target\").\n\n##### Node Functions\n\nThere are multiple functions that you can override to implement your node logic:\n\n| Function       | Description                                    |\n| -------------- | ---------------------------------------------- |\n| `Run`          | Called every time your node runs. You have to return the new state of your node.|\n| `OnInitialize` | Called the first time your node starts running.  |\n| `OnStart`      | Called when your node starts running.                 |\n| `OnStop`       | Callled when your node returns `Success` or `Failure`. |\n\n### Blackboard\n\nThe Blackboard contains parameters that provide useful information to the nodes, allowing them to communicate with each other and with the components of the scene.\n\n#### Add Parameters\n\nIn the editor do the following:\n\n1. Press the `+` button in the upper right corner of the Blackboard.\n2. Select the parameter type you want to add.\n3. Double-click or `Right-Click \u003e Rename` on the parameter to give it an appropriate name.\n\n#### Get/Set Parameter Values\n\nYou can manage your parameters in your code through the [BehaviourTreeRunner functions](#behaviourtreerunner). There are several ways to get to the value of a parameter.\n\n##### By BehaviourTreeRunner Functions\n\nYou can *Get* or *Set* the parameter values directly with the `GetParameterValue\u003c\u003e` and `SetParameterValue\u003c\u003e` methods.\n\n\u003cdetails\u003e\n\n\u003csummary\u003e Example \u003c/summary\u003e\n\n```CSharp\npublic string ParameterName;\n\nprotected override NodeState Run(BehaviourTreeRunner runner)\n{\n    var parameterValue = runner.GetParameterValue\u003cint\u003e(ParameterName);\n    runner.SetParameterValue(ParameterName, 5);\n}\n```\n\n\u003c/details\u003e\n\n\u003e [!WARNING]\n\u003e This method has an impact on the CPU since your `BehaviorTree` looks for the parameter every time you call any of the above methods. If you find yourself frequently reading and/or writing to a parameter value, it is recommended to use the following method.\n\n##### By Parameter Reference\n\nYou can get a reference to the parameter that you want to use with the `GetParameter\u003c\u003e` function in your `BehaviourTreeRunner` and then, *Get* or *Set* his value with the Value property.\n\n\u003cdetails\u003e\n\n\u003csummary\u003e Example \u003c/summary\u003e\n\n```CSharp\npublic string ParameterName;\n\nprivate BehaviourTreeParameter _Parameter;\n\nprotected override void OnInitialize(BehaviourTreeRunner runner)\n{\n    _Parameter = runner.GetParameter\u003cint\u003e(ParameterName);\n}\n\nprotected override NodeState Run(BehaviourTreeRunner runner)\n{\n    var value = _Parameter.Value;\n    _Parameter.Value = 5;\n}\n```\n\n\u003c/details\u003e\n\n\u003e [!TIP]\n\u003e There is a class called `BehaviourTreeParameterRef` that does the same thing eliminating the need for a string.\n\u003e\n\u003e \u003cdetails\u003e\n\u003e\n\u003e \u003csummary\u003e Example \u003c/summary\u003e\n\u003e\n\u003e ```CSharp\n\u003e public BehaviourTreeParameterRef Parameter;\n\u003e\n\u003e protected override void OnInitialize(BehaviourTreeRunner runner)\n\u003e {\n\u003e     Parameter.Bind(runner);\n\u003e }\n\u003e\n\u003e protected override NodeState Run(BehaviourTreeRunner runner)\n\u003e {\n\u003e     var value = Parameter.Value;\n\u003e     Parameter.Value = 5;\n\u003e }\n\u003e ```\n\n\u003c/details\u003e\n\n#### Create Custom Parameters\n\nTo create your own parameters, you have to:\n\n1. Create a new C# script.\n2. Inherit from `BehaviourTreeParameter`.\n3. Add the `AddParameterMenu` attribute on top of your class.\n\n##### AddParameterMenu Attribute\n\nThis attribute requires two parameters:\n\n- **Path**: the menu path of the parameter (*e.g. \"Component/NavMeshAgent\"*).\n- **GroupLevel** (*optional*): determines what parameters it will be grouped with. A higher number means it will be further down his submenu.\n\n### BehaviourTreeRunner\n\nThis **MonoBehaviour** is responsible for running your `BehaviourTree` and works as an interface to interact with it.\n\n#### Inspector\n\nHere you can assign the `BehaviourTree` you want to run, decide how or when you want to run it and override parameters of the Blackboard.\n\n#### Main Functions\n\n| Function | Description |\n| -------- | ----------- |\n| `GetParameter\u003c\u003e` | Returns the value of a parameter in the Blackboard. |\n| `GetParameterByRef` | Returns a reference to the parameter in the Blackboard. |\n| `GetParameterByRef\u003c\u003e` | Returns a generic reference to the parameter in the Blackboard. If the passed generic type is not correct, it returns null. |\n| `SetParameter\u003c\u003e` | Sets the value of a parameter in the Blackboard. |\n\n## Attributions\n\nThe Behaviour Tree tool in this repository was expanded from the one created by **TheKiwiCoder** in [this video](), whose repository you can find [here](https://github.com/thekiwicoder0/UnityBehaviourTreeEditor).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoshitinencoded%2Fai-behaviour-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoshitinencoded%2Fai-behaviour-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoshitinencoded%2Fai-behaviour-tree/lists"}