Every behaviortree task gets called two times in a row

Hello!

I’ve made my AI character to jump and right after the jump phase the stones rain down from the ceiling. However, when my AI character jumps the jump task executes twice in a row, same with spawnstones task.

Here’s my behaviortree setup:


So when the character has jumped, but is not on ground, the conditional loop runs until the condition is true and the stones fall down, so the loop will start over again. I am still not aware why the jump and summonstones tasks run two times in a row. (I know the last node should fail in order to be correctly set up, but at the moment it's the last node of that branch, so (I think?) it doesn't matter.

Waiting for your response!

With regards!

As always… I keep doing silly mistakes myself. For some reason I had started behavior tree two times with different functions:


BT_Component->StartTree(*Character->BehaviorTreeAsset);

RunBehaviorTree(Character->BehaviorTreeAsset);


As UBehaviorTreeComponent’s function StartTree checks whether tree isn’t already running, it starts the tree

void UBehaviorTreeComponent::StartTree(UBehaviorTree& Asset, EBTExecutionMode::Type ExecuteMode /*= EBTExecutionMode::Looped*/)
{
	// clear instance stack, start should always run new tree from root
	UBehaviorTree* CurrentRoot = GetRootTree();
	
	if (CurrentRoot == &Asset && TreeHasBeenStarted())
	{
		UE_VLOG(GetOwner(), LogBehaviorTree, Log, TEXT("Skipping behavior start request - it's already running"));
		return;
	}
        // irrelevant at the moment

As AAIController's function RunBehaviorTree doesn't check that, behavior tree will run behavior tree once more, which makes me question which of these functions should I use to initalize the behaviortree.

Waiting for your response!
With regards!

1 Like

@Rasponien, thanks for your post! You are not alone in making this mistake :slight_smile: