Any way to dynamically select a behavior subtree?

When you add a BTTask_RunBehaviorDynamic to your tree you get to specify a ‘tag’ that will identify given place in the BT as potential sub-BT injection location. Then at runtime you can use BTComponent->SetDynamicSubtree to inject given BT into that spot. This is done per AI so you can have on big BT that defines overall behavior structure and use dynamic BTs to differentiate between different AI types.



1 Like

Hi, here’s my problem.

I have a number of different AI, that want to use one general behaviour tree for determining overall state, like detecting an enemy or patrolling, but I want them all to use their own individual attack routines.

Now, I realize I can build the attack routines inside the AI’s own BP, but that seems clunky for a number of reasons, including having to clutter their event graph with behaviours, and build call backs to the Behaviour tree to tell it when it’s done attacking. Especially since the attack routines themselves should be state machines - like a behaviour tree.

Or I could cut-and-paste my behaviour trees and just modify the attack section of it.

Neither of those seem like great solutions.

There is a ‘run behaviour dynamic’ task, but it doesn’t actually let me pass it a behaviour tree as a parameter from the blackboard - tbh I don’t understand what the run behaviour dynamic task is intended to do.

What’s the design pattern supposed to be here?

Ok thank you. And I get the behaviour tree component by casting the ‘brain’ component on my AI controller after I run my behaviour tree?

Also, the blackboard has to match for the dynamic subtree? There’s no such thing as a ‘local’ blackboard that a particular tree can use?

Thanks, seems to work so far. Although I’m a little disappointed that MieszkoZ’s comment here seems to be the only place on the entire internet where these nodes are explained in English.

1 Like