How do I use RunBehaviorDynamic in the behavior tree?

Hello,

I need a bit of help understanding how to use the RunBehaviorDynamic task in behavior trees. I am working on an open-world RPG game and I wanted to create a single AI that all NPCs in the game would use. This AI would use a master behavior tree that would link to other behavior trees for combat and their occupational work.

For this to work, I want the ability for NPCs placed in the world to be set occupations and the master behavior tree to change the tree that will run for their work behavior. To avoid having to choose between RunBehavior tasks for every occupation possible, I wanted to use the RunBehaviorDynamic task and change which behavior tree it would run depending on the occupation selected.

I have searched around for instructions on how to use this task but have come up empty so far, any advice on how to use this task or how to get around using it would be much appreciated.

Indeed there is almost no information about that. I discovered that it is meant to be used with the node “set dynamic subtree”. However it needs a behavior tree component. I have no idea how to use this component, I’ve tried to add it to the pawn, to the ai controller…I found no way to add this component somewhere or to get a reference to it and the only infos available for the component are for c++. Maybe it is not available for blueprints.

I hope someone will come with more informations.

After digging a bit more, here is how to access the component. Now just have to find out how to use gameplay tags, that is something I have never seen used in a tutorial or a marketplace product :

3 Likes

That’s further than I’ve gotten, gonna try and play around with the tags and see what I can find.

So I think I’ve figured out how to use it.

When selecting the Run Behavior Tree task in my behavior tree, I was able to create the Gameplay Tag “Test Tag”, which can also be done in the Project Settings (I accidentally created a sub-tag called “Test” that I wasn’t able to delete, but it wasn’t important).

Then in the AI Controller for my character, I used the Set Dynamic Subtree node and selected the same tag as is defined in the behavior tree. This managed to change the behavior asset after runtime, and I was even able to make it swap back-and-forth between two trees.

I did try this in a different blueprint other than the Controller, but it wouldn’t work for me; only seems to work in the Controller blueprint.

Hopefully this works for everyone :slight_smile:

1 Like

Hey SebGallop,

Thanks for asking the question here previously, I am currently trying to research how to use dynamic BT’s and your post has helped already.

As for anyone still reading this, you can actually change the dynamic behavior tree from outside of the AIController. You will simply need to find and reference this AIController and get its braincomponent. (In BeginPlay I did a ‘Get all actors of class’, keep in mind this is just quick prototyping, you should change this for an actual game).


These screenshots are taken from my player bp. I can switch between two trees using the 1 and 2 key. Some things to keep in mind. Make sure the tag you use to call your subtree is the same as your inject tag. Also, so far, it seems to me that all behaviour trees will also need the same Blackboard. I will have to experiment with this though.

Hope this clarified it a little further :smiley:

2 Likes