From 8fcb4690793ae4ada5db434221c44d1525071a64 Mon Sep 17 00:00:00 2001 From: Dmitry Baltin Date: Wed, 3 Sep 2025 21:07:40 +0200 Subject: [PATCH 1/2] Update README.md --- README.md | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8aa0fde..ff3d37a 100644 --- a/README.md +++ b/README.md @@ -1 +1,57 @@ -# UnitaskFBT \ No newline at end of file +![FBT_Logo](.docs/fbt_icon.png) + +# UnitaskFBT + +UnitaskFBT is the second version of the [Functional Behavior Tree (FBT)](https://github.com/dmitrybaltin/FunctionalBT) project, designed for building sophisticated AI in Unity or C# projects. + +Unlike classical FBT, this version uses asynchronous functions, allowing you to write compact, readable, and maintainable code for complex AI behaviors involving long-running actions. + +## Why UnitaskFBT? + +Building complex AI often requires sequences of actions that take several seconds to complete. For example, an NPC attack may involve: +- Pausing to aim +- Preparing to jump +- Jumping +- Hitting the target or playing a miss animation +- Chaining into combos +- Reacting to the player’s actions during the attack + +Classical behavior trees require multiple state variables and constant checks to manage these sequences, which can make code messy and hard to debug. +With **UnitaskFBT**, you can use async/await syntax to handle long-running actions naturally, keeping your code simple, readable, and efficient. + +## Key Features + +- Full async support – Perform long-running actions efficiently without extra flags or checks. +- Boolean node results – Nodes return true = Success or false = Fail. No Running state clutter, simplifying logic. +- Compact, readable code – Makes complex AI logic easier to understand and maintain. +- Inherited FBT advantages – Memory efficiency, performance, and debug-friendly behavior. + +## Example of Usage + +```csharp + await npcBoard.Sequencer(c, //Sequencer node + static async (b, c) => await b.FindTarget(), //Action node realized as a delegate Func> + static async (b, c) => await b.Selector(c, //Selector node + static async (b, c) => await b.If(c, //Conditional node + static b => b.TargetDistance < 1f, //Condition + static async (b, c) => await b.MeleeAttack()), + static async (b, c) => await b.If(c, + static b => b.TargetDistance < 3f, + static async (b, c) => await b.RangeAttack()), //RangeAttack() is the only continuous function in this BT allowing be in the running state + static async (b, c) => await b.If(c, + static b => b.TargetDistance < 8f, + static async (b, c) => await b.Move()), + static async (b, c) => await b.Idle())); +``` + +Notes: +- Each tree node is an asynchronous function, not an object. +- The entire tree is also an asynchronous function, not a static object. +- The construction static async (b, c) => await … in each line may look verbose, but it’s a small price to pay for the huge advantages of an asynchronous behavior tree. +- If a node needs to continue execution in the next cycle, it does not return Running. Instead, it suspends itself (e.g., using await UniTask.Yield()). In the example above, this happens inside RangeAttack(). +- Since there is no Running state, nodes simply return a boolean (bool) rather than a Status, which simplifies the logic. +- All nodes accept a CancellationToken for operation cancellation. +- No closures are used; only static delegates are employed, which avoids additional memory allocations. + +For a detailed comparison between UnitaskFBT and a classical FBT, see this repository [FbtExample](https://github.com/dmitrybaltin/FbtExample) + From 9db287b50db2790288f36b5ca2726bd079b8028c Mon Sep 17 00:00:00 2001 From: Dmitry Baltin Date: Wed, 3 Sep 2025 21:09:58 +0200 Subject: [PATCH 2/2] chore(ci): Incremented version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4ed1423..9c27ed7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.baltin.ufbt", - "version": "0.5.3", + "version": "0.5.4", "displayName": "UniTaskFBT", "description": "Async Functional Behavior Tree implementation based on UniTask", "unity": "2021.2",