Stop Logic and/or Stop Tree dont shut down the tree when switching

First-chance exception at 0x000007FEDB6E4491 (UE4Editor-RRDevelop-Win64-DebugGame.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
Unhandled exception at 0x000007FEDB6E4491 (UE4Editor-RRDevelop-Win64-DebugGame.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

I just put;
BrainComponent->StopLogic("");

In my AI class, which inherits from aicontroller.

I don’t think the BP stuff is working either, actually. Its just running one behavior tree over another…

Hi All

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?

Thanks!

Hey,

it would be nice if you could show us the Error Message and the C++ Code.

Where it breaks?

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?

Ok so I called;

BehaviorComp->UBrainComponent::StopLogic("");

And that didnt hang. But, same as using

BehaviorComp->StopTree();

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!

Not really sorry. Like i said, i never worked with that.

But googling shows me that the BrainComponent is inside the AiController. So where exactly are you calling your StopTree()?

The AIController should have a pointer to the BrainComponent.

Looking into the API: AAIController | Unreal Engine Documentation

Shows that it really has this BrainComponent Pointer.

http://puu.sh/gB4rY/6bda85bad8.png

So i guess getting the AI Controller and StopLogic on its BrainComponent should do what you want :X But i could be wrong here.

if i go BrainComponent->StopLogic("");
From the AI controller, it’s NULL.

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.

Cheers,

–mieszko