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
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.