[4.11] C++ Behaviour tree not running

Hi guys,

I’m working with a behavior tree in UE4 4.10 (C++ and Blueprint) and my behavior tree was working fine but since I switch to 4.11 my behavior tree isn’t doing anything. At least the first Blueprint Service not showing any print to Screen in the event “Receive Tick AI”. Maybe I’ve done something wrong, but I don’t find what is it.

Here my following code:

Controller.cpp

#include "Invaders.h"
#include "InvadersBuildingsAIController.h"

AInvadersBuildingsAIController::AInvadersBuildingsAIController()
	: AAIController()
{
	static ConstructorHelpers::FObjectFinder<UBlackboardData> bb(TEXT("BlackboardData'/Game/Buildings/BB_Building.BB_Building'"));
	static ConstructorHelpers::FObjectFinder<UBehaviorTree> bt(TEXT("BehaviorTree'/Game/Buildings/BT_Building.BT_Building'"));
	Blackboard = CreateDefaultSubobject<UBlackboardComponent>("Blackboard");
	blackboardData = bb.Object;
	behaviorTree = bt.Object;
}

void AInvadersBuildingsAIController::BeginPlay()
{
	Initialize();
}

void AInvadersBuildingsAIController::Initialize()
{
	if (!Blackboard->InitializeBlackboard(*blackboardData))
	{
		GEngine->AddOnScreenDebugMessage(-1, 1, FColor::Red, "Could not load Blackboard");
		return;
	}
	Blackboard->SetValueAsFloat("AttackCooldown", 0.0f);

	AInvadersActor* npc = Cast<AInvadersActor>(GetPawn());
	if (npc)
	{
		Blackboard->SetValueAsObject("SelfActor", GetPawn());
		if (!RunBehaviorTree(behaviorTree))
			GEngine->AddOnScreenDebugMessage(-1, 1, FColor::Red, "Could not run behavior");
		else
			GEngine->AddOnScreenDebugMessage(-1, 1, FColor::Green, "Run Behavior Tree");
	}
}

Controller.h

#pragma once

#include "Invaders Base/InvadersActor.h"
#include "AIController.h"
#include "Runtime/AIModule/Classes/BehaviorTree/BlackboardComponent.h"
#include "Runtime/AIModule/Classes/BehaviorTree/BehaviorTree.h"
#include "InvadersBuildingsAIController.generated.h"

UCLASS()
class INVADERS_API AInvadersBuildingsAIController : public AAIController
{
	GENERATED_BODY()

public:
	AInvadersBuildingsAIController();

	virtual void BeginPlay() override;

	void Initialize();

	UPROPERTY(EditAnywhere, Category = "Invaders AI")
		UBlackboardData* blackboardData;

	UPROPERTY(EditAnywhere, Category = "Invaders AI")
		UBehaviorTree* behaviorTree;
};

Behavior Tree : BT_Building

Blueprint Service : BTServ_FindEnnemies

87438-ue4editor_2016-04-19_18-38-11.png

In the Controller.cpp, the function “RunBehaviorTree(behaviorTree)” is working and it prints the debug message “Run Behavior Tree” like it should be.
Right after the event Receive Tick AI, I try to print “Hello” but it’s not showing anything and consequently the rest of the blueprint and the behavior tree not working.

If someone knows what happens, I will gladly hear it.

Thanks for the future answers.

Hi guys,

I still have this problem and don’t know why.
Any idea of what is the problem?

Thanks

Hey there - having the same issue. BehaviourTree working fine in 4.10, does not work at all in 4.11.

if (AICharacter && AICharacter->AIBehavior && AICharacter->AIBehavior->BlackboardAsset)
{
	BlackboardComponent->InitializeBlackboard(*AICharacter->AIBehavior->BlackboardAsset);
	
	BlackboardProperties.TargetKeyID = BlackboardComponent->GetKeyID("Target");
	BlackboardProperties.LastSensedLocationID = BlackboardComponent->GetKeyID("LastSensedLocation");
	BlackboardProperties.NextWeaponID = BlackboardComponent->GetKeyID("NextWeapon");
	BlackboardProperties.NextWeaponLocationID = BlackboardComponent->GetKeyID("NextWeaponLocation");

	BlackboardProperties.ShouldProcessCommandsID = BlackboardComponent->GetKeyID("ShouldProcessCommands");
	BlackboardProperties.CommandTypeID = BlackboardComponent->GetKeyID("CommandType");
	BlackboardProperties.CommandActorID = BlackboardComponent->GetKeyID("CommandActor");
	BlackboardProperties.CommandLocationID = BlackboardComponent->GetKeyID("CommandLocation");

	BehaviourComponent->StartTree(*AICharacter->AIBehavior);
}

Did you find an answer for this problem? I am having the same issue

Did you get to solve this problem? I am having the same issue :frowning:

I would suggest starting a new question, with your problems. This question is over 4 years old.