External Behaviour Trees Best Practices

daphii

New member
Hello!

For my last project with BD, I surely didn't take advantage of what it was capable of, and I don't think I quite understood it until i was too late in the project to rewrite it all. This time I want to try to better utilize what it is capable of, so ive been going through the docs a lot closer, and I'm stuck on something with External Behaviour Trees!

In all the examples, these external trees are for focused singular(ish) tasks shared between different trees. In the TD game im working on right now, enemies are either following the path or attack, very simple. All enemies except bosses can share an identical tree. Not just parts, but the exact tree. Is there a way to do this beyond creating a new tree for every single one, and then calling the external tree from within it? I might be reading the docs wrong, but I'm just looking for a way to share an entire tree, between a bunch of different different enemy objects!
 
Sorry I missed this.

External trees are great for reusability. In your situation do the standard enemies share the same sub-branches as the boss? Since all of the enemies are the same external trees do not provide any sort of advantage there, but if for example their attack branch is the same as the boss then you could get some reusability there.

With that said, don't use external trees just because you think that you need to use them. If you're happy with your workflow then there's no reason to use them.
 
Thanks for your reply!
To outline my question a bit better:

In my last projects I had 3 enemy types, which instead of sharing a whole tree, just had identical trees, so I had to constantly make the changes in 3 spots. When I created the bosses, this became a bigger problem as I now had 13 more trees to manage more or less the same changes, lots of unnecessary work!

In my upcoming project, one of my goals with properly using BD (as it seems to have a TON of potential for me, if I learn how to utilize it better) is to take advantage of shared trees!

What I'm envisioning for enemies is something simple like:

Normal Enemies
Start --> if HasTarget --> Attack
__________else_________--> PathToGoal


Elite
Enemies
Start --> if SpecialReady --> UseSpecial
__________else____________--> if HasTarget --> Attack
______________________________else_________--> PathToGoal

Given this structure I can reuse Attack and PathToGoal in all trees, and UseSpecial in Boss trees as external trees. This usage in particular seems pretty clear from the docs (while I haven't tried it yet).

Optimally the enemies can be reduced down to 5 total trees, Normal (containing Attack and PathToGoal) and Elite (containing both previous as well as UseSpecial). I'm hoping to extrapolate this solution to manage all the logic for the towers and friendly units as well, but this was the simplest use case to outline!

What I seem to have missed is how to share the normal enemy tree with all normal enemies so I don't need to make an manage a separate tree for each prefab! I'm sure this is something I have just missed!

Thank you!
 
Last edited:
Yes, that sounds like a perfect use case for external trees. You can also override variables so each enemy type has different variable values. For example, your regular enemy may want to have an attack strength of 1 while your boss has a strength of 10. You can override the variable values on the Behavior Tree Reference task making reusability even easier.
 
Back
Top