Warning : is this the best way ? No. Nothing is perfect. This plugin was designed for my own game, I wanted to make it simple and threw programming's best practices out the window. It may have some flaws, but for my case it was perfect. Try it for 15 minutes and if you don't think it fits your use case, no harm done, don't waste your time. Otherwise, I hope you enjoy the plugin!
Clone or download the addons folder and add it in your project.
OR
Download the plugin via the Godot Asset Library:
Then activate the plugin in your Project Settings.
- It is a behavior tree just like any other, no magic here, if you need to learn the concept, a quick google search will get you a long way.
- The addon works with only a single script, you can however combine multiple BTree's in one parent. For example, you can separate your animation tree from your logic tree.
- You can add BTREE as a child to any node. You must add a script to the BTree or the plugin will error!
- Select the BTREE node and switch to the BTree Editor (BTEditor) window in the top menu.
- You will need a node to connect to the root or it will not run.
- To create a task / leaf node, you will need to make a function that follows this naming scheme:
task_<methodname>(task)
. For example, a function that prints "hello world" can have the nametask_printhelloworld(task)
. - The function must also have the argument
task
. This argument is used for flow control. - You can call functions on this argument. You can call
succeed()
to complete the task on success orfailed()
to complete on failure. The task status keeps running if you do not call anything, that means in the next tick it will be called again until you callsucceed()
orfailed()
. To determine if a task is initialized or not you can callis_init()
in the control flow. If it returns true then the node is initialized, this is useful for a task that requires something to be initialized before running, for example, computing a path.
- You can also pass your owns arguments to the task from the Tree Editor. This is for example useful when creating some kind of dialogue system for NPCs or to play an animation.
- You can look up the rest of the node behavior by hovering your mouse which displays a tool tip you can use. The is also a help button that explains some basic controls like copying, deleting and saving nodes etc..
- You can visualize the current running BTree instance in your game by clicking the debug button, your game must be running or debugger will not show anything.
- Currently you can only see the status but if you need anything more advanced or fancy, feel free to create an issue.
- The Debugger will currently does not work on mobile, only local desktop machine is supported.
- You can pause a BTree while debugging by pressing pause.
- You can step a BTree while it is paused by pressing and holding the step button.
- To perform a hot reload go to the BTEditor while your project is running, perform your changes and afterwards after press save or CTRL + S, this will update your whole project, not only the running tree but also the same tree after it gets instanced.
- The tutorial is credited to this Youtube channel Vic Ben
- This is a great tutorial on how to use the plugins Video Link
- Again I have to thank Vic Ben for making these tutorial videos.
This is here to keep track of changes from https://github.com/fian46/addons-btree
- 9/7/2021
- Refactored many editor nodes to inherit from a single class to make it easier to modify more general things.
- Added ability to rename nodes with undo-redo functionality
- Fixed issue with changing tabs and BTree not saving
- Modified some nodes to stop using call_deferred since it was causing loading after editor was closed and reopened to not populate fields
- Generalize wait and random_wait to inherit from a common class.
- Generalize repeat and random_repeat to inherit from a common class.
- A way to have "branches" of trees that can be added to a tree. When added it would run everything inside inner tree. Making it easier to organize and share behaviors.
- Feel free to contribute if you would like!
- I will probably be adding features as I need them for my own game.