I have followed many tutorials and have done EnemyAIController like this:
EnemyAIController.h:
#pragma once
#include "CoreMinimal.h"
#include "AIController.h"
#include "EnemyAIController.generated.h"
UCLASS()
class OLIVIA_API AEnemyAIController : public AAIController
{
GENERATED_BODY()
public:
AEnemyAIController();
virtual void OnPossess(APawn* InPawn)override;
protected:
UPROPERTY(Transient)
class UBlackBoardComponent *BlackBoardComp;
UPROPERTY(Transient)
class UBehaviorTreeComponent *BehaviorTreeComp;
uint8 EnemyKeyID;
};
EnemyAIController.cpp:
#include "EnemyAIController.h"
#include "BehaviorTree/BlackboardComponent.h"
#include "BehaviorTree/Blackboard/BlackboardKeyAllTypes.h"
#include "BehaviorTree/BehaviorTree.h"
#include "BehaviorTree/BehaviorTreeComponent.h"
#include "EnemyCharacter.h"
AEnemyAIController::AEnemyAIController()
{
BlackBoardComp = CreateDefaultSubobject<UBlackBoardComponent>(TEXT("BlackBoardComp"));
BehaviorTreeComp = CreateDefaultSubobject<UBehaviorTreeComponent>(TEXT("BehaviorTreeComp"));
}
void AEnemyAIController::OnPossess(APawn * InPawn)
{
Super::OnPossess(InPawn);
AEnemyCharacter *c = Cast<AEnemyCharacter>(InPawn);
if (c && c->botBehavior)
{
BlackBoardComp->InitializeBlackBoard(*c->botBehavior->BlackboardAsset);
EnemyKeyID = BlackBoardComp->GetKeyID("TargetActor");
BehaviorTreeComp->StartTree(*c->botBehavior);
}
}
Even with the included headers, the .cpp can’t recognize UBlackBoardComponent and when compiling it complains that error C2027: use of undefined type ‘UBlackBoardComponent’.
I have tried other ways like moving those includes to the EnemyAIController.h, but the error persists.
Please note that UBehaviorTreeComponent is good, only UBlackBoardComponent is undefined.
Also I did add “AIModule” to the .Build.cs, then rebuild the solution, but still the error persists.
I clicked and opened BehaviorTree/BlackboardComponent.h and it looks fine.
...
class UBrainComponent;
...
UCLASS(ClassGroup = AI, meta = (BlueprintSpawnableComponent))
class AIMODULE_API UBlackboardComponent : public UActorComponent
{
...
Am I missing some other includes than BehaviorTree/BlackboardComponent.h?
Any ideas? Thanks.