How to stop/change a behavior tree using blueprints

We are using the Run Behavior blueprint node to start a behavior tree in the AIController and that is working great, but I don’t see a way to stop a behavior tree from running using blueprints. I also don’t see a way to change the behavior tree that is running. I tried just calling RunBehavior and setting it to None, but it has no effect. Also, I tried calling Run Behavior with another behavior tree, but it ended up running both at the same time instead of changing the behavior tree. It was quite strange.

What we want to do is have a few different behavior trees and change them on the AIController based on what job the AIController should be doing. Is this not a good method? Should we instead create one huge Behavior Tree that tries to handle all possible jobs?

I found the following function in the C++ source file BehaviorTreeComponent.cpp: UBehaviorTreeComponent::StopTree(). If I expose this method to blueprints via C++, do you think it will do what I want?

from what I have found this is best. Using a service to change the flow of a Behavior tree. All logic can go in one controlled by a service.

I have alot in mine as well but the AI is in the form of a state machine so everything seems to operate will with a few AI Monsters on the field I can try adding 50 per spawn sphere and see what happens.

Yeah, this is what I am currently doing. Using a service to toggle between the modes. I am worried about the performance though. This service is going to run hundreds or thousands of checks that are not needed. Since services are not event driven, I try to only use them for AI actions that need to respond instantly. In this case the mode that needs to be run may rarely ever change, but the service is still going to need to execute at least once every 5 seconds to make sure it doesn’t take too long to change modes. Seems like a lot of wasted executions. I am hoping there is a better way.

I’ve investigated running a BT on top of other BT and in trivial case it works. This suggests your BT contains a setup surfacing a bug. Is there anything about your BT you can share so I can give it another debug run? What kind of nodes are you using, are there any BP-implemented nodes?

The design is that it should work and if it doesn’t then it’s a bug.

What we want to do is have a few different behavior trees and change them on the AIController based on what job the AIController should be doing. Is this not a good method?

Yes, it’s a good pattern.

Should we instead create one huge Behavior Tree that tries to handle all possible jobs?

No. In many different circumstances a BT is restarted from the root node, and the bigger the BT the more CPU cycles wasted to settle on a branch to execute.

I found the following function in the C++ source file BehaviorTreeComponent.cpp: UBehaviorTreeComponent::StopTree(). If I expose this method to blueprints via C++, do you think it will do what I want?

It should.

I’m terribly sorry we’re missing some basic functionality, like stopping AI’s behavior for example. I’m currently working to address that :wink:

Cheers,

–mieszko

I’m terribly sorry we’re missing some
basic functionality, like stopping
AI’s behavior for example. I’m
currently working to address that ;)"

ouch I come here to know how to stop I find this, Hahahahaha, would It is working, please, in the 4.5 version?

Turns out it’s not that easy, and there’s so many things to take care of… :confused:
So I guess you need that? More than other missing things? I’m serious, let me know.

@MieszkoZ

“I’m currently working to address
that”

Sad when 6 months later nothing has changed…

Thanks for the answer.
There are things I need much more (like DetourCrowds available from Blueprints, or being able to export a blueprint game with plugins).
I am really satisfied with the Behaviour Tree at the moment, but I have not tried my game with 2000 AIs running around. And I guess then it makes a difference whether I check unnecessary stuff 10 times per second on every AI, which could be done so much more intelligent with events. It’s just what Dartanlla wrote:

I am worried about the performance
though. This service is going to run
hundreds or thousands of checks that
are not needed. Since services are not
event driven, I try to only use them
for AI actions that need to respond
instantly. In this case the mode that
needs to be run may rarely ever
change, but the service is still going
to need to execute at least once every
5 seconds to make sure it doesn’t take
too long to change modes. Seems like a
lot of wasted executions.

The “2000 AIs” is a realistic number my game will probably exceed at some time, its a real time strategy game connected with some economical simulations, so every player may have ~300 Civilians that are doing things (and are completely driven by behavior tree) and additional all the normal units which receive commands from the player, but also are automatically checking for enemy’s coming into their shoot or combat distance, normally moving around or patrolling, and so on.
Things like check whether an enemy is inside the shoot/combat distance can probably be done only once a second, but updating the location where to walk has to be done ~10 times a second, if the player right clicks somewhere to let the units move, he doesn’t want to feel a “lag” until the units really start moving.

2000 AIs in a BP game where every AI is autonomous? Have you tried to put this amount of AI in yet? I can already tell you that movement and animation will be your biggest performance problem now. Of course it depends on details, but processing BTs won’t be your biggest CPU bottleneck.

Having said that, I’ll see what I can do.

Regarding DetourCrowds it would be ideal if you created a new thread describing what amount of control over crowds you’d expect.

Wow, your answer speed is incredibly fast, it’s the direct contrast to what I experienced with the answer hub yet (3 questions asked 2 weeks ago, not even a single answer received). So I really have to say thank you :wink:

I have not tried the amount of AI yet, but except you mean that blueprints in general would be too slow for that compared to c++, I don’t get why “movement and animation” should be the problem. Animation can be really simple because the player is “far” away from the AIs. I guess with “movement” you are talking about navigation/pathfinding? I don’t know how exactly the navmesh in UE4 works internally, but most of the units will probably not move all at once, and if they do, I don’t mind when the game laggs for a second because its generating the paths for all of them (that’s what I experienced in other RTS games).

Where should I create a new thread about DetourCrowds? Here on the answerhub or in the forums? I just want to be able to use DetourCrowds from blueprint, with same control over them I would also have in a c++ project. I think your blueprint team already knows that DetourCrowds are still missing in blueprint only projects. It’s really easy to enable them in c++ (just change the PathFollowingComponent to CrowdFollowingComponent in the AIController).

(…) So I really have to say thank you :wink:

Pleasure is mine :slight_smile:

When I say “movement” I mean actually moving AI characters over the collidable geometry. Even the stationary ones need to be updated in case the ground has been removed from under their feet.

However, recently we’ve implemented “navmesh walking” as an alternative to regular walking, and is a lot faster, but requires navmesh, and, is only as precise as the generated navmesh (which might be fine in your case).

Where should I create a new thread about DetourCrowds? Here on the answerhub or in the forums?

Here, I don’t go to forums too often :wink:

I just want to be able to use DetourCrowds from blueprint, with same control over them I would also have in a c++ project. I think your blueprint team already knows that DetourCrowds are still missing in blueprint only projects. It’s really easy to enable them in c++ (just change the PathFollowingComponent to CrowdFollowingComponent in the AIController).

Because of the way DetourCrowds have been implemented it’s a bit problematic to easily expose it to BP use until Blueprint Team gives us generic BP ways of changing component classes. I’d also would like to know what exactly you’d like to control, and if you need access to the crowd manager as well… Just create a new thread (here).

In general, regarding performance, I don’t even think about BP vs C++ performance. I mean, that using default, vanila components and characters may not be enough to make your game efficient. It should be fine for prototyping, but you need to be ready to implement some dedicated, batched AI solutions for managing big numbers of agents. We have plans for such systems, but no one is actively working on it at the moment.

Also, I’ve just submitted a change allowing you to stop and restart AI logic: github, so I’m closing this thread :slight_smile:

I’ve just submitted a change that allows BP users to stop and restart AI logic: github. All you need to do is get the BrainComponent from your AI controller and call StopLogic or RestartLogic. Enjoy (sorry it took so long!).

Thanks! So I will create a new thread about DetourCrowds here on the answerhub. I still have the feeling that much more people are reading the forums, there I always got fast answers on my question.
I think this whole “dividing” into answerhub and forums is a bit suboptimal, because most people are mostly reading one of them (and most people seem to only read the forums).
Just one thing left here: I can’t find anything about this “navmesh walking” you mentioned. Does it has a different name or is it so recently added that it is not yet mentioned anywhere?

It turns out navmesh walking (MOVE_NavWalking movement mode) has not been merged to master branch yet, so no wonder you can’t find it :smiley: Sorry, you’ll have to wait for it a bit.

Regarding forums, well, there’s plenty of people that can answer your questions there. If no one there knows an answer, or it’s a bug report, or feature request, you come here. Exposing DetourCrowds is a feature request :wink:

You haven’t used any of the tags I’m observing :smiley: I’ll reply today (a bit busy at the moment).

@MieszkoZ
You see, that’s why I dont like the answerhub. I created the thread 4 days ago, and haven’t received any answer yet. So it just feels useless for me to create such threads.

I have used the tag “detour”, and you are observing this one :wink: What better tags should I have used?

Then I must have totally missed it :confused: Guess how many emails I’m getting every day :wink: No worries, I got something for you. Stay tuned.

Stopping works, but RestartLogic won’t, using 4.24.3