I’ve probably messed up somewhere, but wondering why, if I create a task for a behavior tree to stop the currently running tree, using StopLogic (BrainComponent), in a BTTask_BlueprintBase, or if I use;
BehaviorComp->StopTree();
Or
BehaviorComp->UBrainComponent::StopLogic("");
In C++, and then switch to a new tree, I end up with several trees running. The ones that I stop -using any of the above methods- just show “steps back” and kick back in.
Is there a way to totally stop a tree when switching?
An access violation error appears because you are using a pointer although it is NULL. If you are using “BrainComponent->StopLogic()” are you sure that “BrainComponent” isn’t null?
It doesn’t stop the tree. I end up with three or four behavior trees running on top of each other. There doesnt seem to be a way to completely shut down a tree, either in BP’s or C++, when switching to another tree.
Na, the StopLogic should work. You are not calling it on the BrainComponent though. The BrainComponent Variable just needs to be filled. You need a valid pointer that points to that Component and then you can call your StopLogic function.
I never worked with Tree in c++, but somewhere you need to have the BrainComponent created and set it to a variable.
So I create a subobject pointer to a braincomponent? I thought braincomponent was an abstract class. Do you have any code of what that would look like- creating a variable that is the braincomponent? Thanks!
AIController's BrainComponent gets set with first call to RunBehaviorTree. It points to a UBehaviorTreeComponent instance, so you can safely cast it. BrainComponent->StopLogic will result in AI’s BT not running, but being able to “restart”. Cast(BrainComponent)->StopTree will stop BT’s activity and remove it from the bt component, so I guess this is what you need.
Just make sure, before calling anything on an “unknown” (of uncertain state) pointer, that the pointer is not nullptr.