{"id":13662527,"url":"https://github.com/SinyavtsevIlya/DOTS-BehaviorTree","last_synced_at":"2025-04-25T10:31:56.012Z","repository":{"id":51331868,"uuid":"397035893","full_name":"SinyavtsevIlya/DOTS-BehaviorTree","owner":"SinyavtsevIlya","description":"Unity DOTS Behavior-Tree implementation","archived":false,"fork":false,"pushed_at":"2021-09-01T15:44:21.000Z","size":36,"stargazers_count":76,"open_issues_count":0,"forks_count":15,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-10T18:43:56.357Z","etag":null,"topics":["behavior-tree-editor","behavior-trees","burst","dots","ecs","unity"],"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/SinyavtsevIlya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-17T00:58:42.000Z","updated_at":"2024-10-29T02:19:53.000Z","dependencies_parsed_at":"2022-09-24T21:52:09.008Z","dependency_job_id":null,"html_url":"https://github.com/SinyavtsevIlya/DOTS-BehaviorTree","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SinyavtsevIlya%2FDOTS-BehaviorTree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SinyavtsevIlya%2FDOTS-BehaviorTree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SinyavtsevIlya%2FDOTS-BehaviorTree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SinyavtsevIlya%2FDOTS-BehaviorTree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SinyavtsevIlya","download_url":"https://codeload.github.com/SinyavtsevIlya/DOTS-BehaviorTree/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250798264,"owners_count":21489053,"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":["behavior-tree-editor","behavior-trees","burst","dots","ecs","unity"],"created_at":"2024-08-02T05:02:01.176Z","updated_at":"2025-04-25T10:31:55.603Z","avatar_url":"https://github.com/SinyavtsevIlya.png","language":"C#","funding_links":[],"categories":["C\\#"],"sub_categories":[],"readme":"# DOTS-BT\nUnity DOTS Behavior-Tree implementation\n\n![title](https://i.imgur.com/iPY6vuX.png)\n \n# Features\n\n- High performance. Zero GC allocations.\n- Easy to use, less to code.\n- 100% ECS-ish. No blackboards, no unrelated systems to think about.\n- Supports all classic composite node types: Selector, Sequence, Repeater.  \n- Conditional aborts support.\n- Creating (and editing) a tree in Unity Editor.\n- Compatible with burst and il2cpp.\n\n# HowTo\n\n## Requirements\n\n`Min. Requirements:` Unity \u003e= 2019.4.18 and entities package \u003e= 0.11.2-preview.1\n\n`Tested on:` Unity 2020.2.3 and entities package 0.17.0-preview.42\n\n## Installation\n\nYou can install the repository using `UPM`:\nJust add this line in Packages/manifest.json:\n\n\"com.nanory.unity.entities.bt\": \"https://https://github.com/SinyavtsevIlya/DOTS-BehaviorTree.git\",\n\n## Usage\n\n### 1) Create a new behavior tree \nBy right-clicking the `Hierarchy \u003e Behavior Tree \u003e Root`\n### 2) Create any nested nodes you need \n(Selector/Sequence/Repeater) doing the same way as shown in first step.\n![nodes-creation](https://i.imgur.com/huR6crY.png)\n### 3) Create your own action or conditional node.\nTo make it you need to create a pair: a component and a system.\n\nAction Node example:\n\n```csharp\n// 1) Create an action node component and (optional) add this attribute.\n[GenerateAuthoringComponent]\npublic struct SeekEnemy : IComponentData { }\n\npublic sealed class BTSeekEnemySystem : SystemBase\n{\n   protected override void OnUpdate()\n   {\n       var beginSimECB = this.CreateBeginSimECB();\n       \n       Entities\n           .WithAll\u003cSeekEnemy\u003e() // 2) Simply add it to your Query.\n           .ForEach((Entity agentEntity, \n           // The parameters below are just up to you. \n           in EnemyLink enemyLink, \n           in LocalToWorld ltw,\n           in StoppingDistance stoppingDistance, \n           in BTActionNodeLink bTNodeLink) =\u003e // 3) But don't forget to add this component in the end.\n           {\n               var position = GetComponent\u003cLocalToWorld\u003e(enemyLink.Value).Position;\n\n               if (math.length((position - ltw.Position)) \u003c stoppingDistance.Value)\n               {\n                   // 4) When you decided that the action was completed successfully, then you need to send the result.\n                   beginSimECB.AddComponent(bTNodeLink.Value, BTResult.Success); \n               }\n               else\n                   beginSimECB.AddComponent(agentEntity, new MoveToDestinationRequest() { Position = position, Speed = 1f });\n           })\n           .ScheduleParallel();\n   }\n}\n```\n\nConditional Node example is very similar except two things:\n\n```csharp\n\n// 1) NOTE: in this case we need to implement interface IConditional. (It's only for conversion/validation purposes, not for runtime)\n[GenerateAuthoringComponent]\npublic struct BTIsEnemyReachable : IComponentData, IConditional{ }\n\npublic sealed class BTIsEnemyReachableSystem : SystemBase\n{\n    protected override void OnUpdate()\n    {\n        var beginSimECB = this.CreateBeginSimECB();\n\n        Entities\n            .WithAll\u003cBTIsEnemyReachable\u003e()\n            .ForEach(\n            (DynamicBuffer\u003cInteractableElement\u003e interactableElements, \n            in EnemyLink enemyLink,\n            in Name name,\n            // 2) NOTE: we need to pass a Conditional Node reference.\n            in BTConditionalNodeLink bTNodeLink) =\u003e\n            {\n                for (int i = 0; i \u003c interactableElements.Length; i++)\n                {\n                    if (interactableElements[i].value == enemyLink.Value)\n                    {\n                        beginSimECB.AddComponent(bTNodeLink.Value, BTResult.Success);\n                        return;\n                    }\n                }\n                // you also able to send \"Fail\" results.\n                beginSimECB.AddComponent(bTNodeLink.Value, BTResult.Fail);\n            })\n            .WithoutBurst()\n            .Run();\n    }\n}\n```\n### 4) Add your newly created nodes in the tree\n// TODO\n### 5) Connect tree to agent\n// TODO\n\n# Advanced Tips\n## How to use conditional aborts\n// TODO (basic usage, priorities)\n## How to react on state changes\n// TODO (enter/exit events)\n\n# FAQ\n\n## Is it posible to use nested trees? \nYes. Since the tree is just a prefab it's easy to make using nested prefabs feature.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSinyavtsevIlya%2FDOTS-BehaviorTree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSinyavtsevIlya%2FDOTS-BehaviorTree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSinyavtsevIlya%2FDOTS-BehaviorTree/lists"}