Download

C++ error for AIController UE4.16

I was trying to create an AI, but Visual Studio can’t find the BehaviorTreeComponent in MyAIContrller.cpp (line 26, 28 and 29).
What am I doing wrong? Any ideas?

MyAiController.h


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "AIController.h"
#include "MyAIController.generated.h"

/**
 * 
 */
UCLASS()
class ROBE_API AMyAIController : public AAIController
{
    GENERATED_BODY()

private:
    /*Behavior Tree component reference*/
    UPROPERTY(EditAnywhere)
        class UBehaviorTreeComponent* BehaviorComp;

    /*Blackboard comp ref*/
    UPROPERTY(EditAnywhere)
        class UBlackboardComponent* BlackboardComp;

public:

    /*Constructor*/
    AMyAIController();

    /*Blackboard key*/
    UPROPERTY(EditDefaultsOnly, Category = "AI")
        FName BlackboardKey = "Target";

    /*Executes right when the controller possess a Pawn*/
    virtual void Possess(APawn* Pawn) override;

    /*Sets the sensed target in the blackboard*/
    void SetSeenTarget(APawn* Pawn);


};



MyAIContrller.cpp


// Fill out your copyright notice in the Description page of Project Settings.

#include "MyAIController.h"
#include "AICharacter.h"
#include "Runtime/AIModule/Classes/BehaviorTree/BehaviorTree.h"
#include "Runtime/AIModule/Classes/BehaviorTree/BlackboardComponent.h"
#include "Runtime/AIModule/Classes/BehaviorTree/BehaviorTreeComponent.h"


AMyAIController::AMyAIController()
{
    //Initialize the behavior tree and blackboard components
    BehaviorComp = CreateDefaultSubobject<UBehaviorTreeComponent>(TEXT("BehaviorComp"));
    BlackboardComp = CreateDefaultSubobject<UBlackboardComponent>(TEXT("BlackboardComp"));
}

void AMyAIController::Possess(APawn* Pawn)
{
    Super::Possess(Pawn);

    //Get the possessed Pawn. If it's the AI Character we created
    //initialize it's blackboard and start it's corresponding behavior tree
    AAICharacter* AICharacter = Cast<AAICharacter>(Pawn);
    if (AICharacter)
    {
        if (AICharacter->BehaviorTree->BlackboardAsset) // the AAICharacter class does not exclude any member "BehaviorTree"
        {
            BlackboardComp->InitializeBlackboard(*(AICharacter->BehaviorTree->BlackboardAsset));
            BehaviorComp->StartTree(*AICharacter->BehaviorTree);
        }
    }
}

void AMyAIController::SetSeenTarget(APawn* Pawn)
{
    //Registers the Pawn that the AI has seen in the blackboard
    if (BlackboardComp)
    {
        BlackboardComp->SetValueAsObject(BlackboardKey, Pawn);
    }
}


The includes you’re looking for are:



#include "BehaviorTree/BehaviorTree.h"
#include "BehaviorTree/BlackboardComponent.h"
#include "BehaviorTree/BehaviorTreeComponent.h"