AIPerceptionComponent in Pawn C++ Doesn't Compile

Hello,
I am having a very basic issue, the code doesn’t compile when I have a UAIPerceptionComponent inside my Pawn class.

Header:


UCLASS(BlueprintType)
class THRAWN_API AAIBasicSensor : public APawn
{
GENERATED_BODY()

public:
UPROPERTY()
UAIPerceptionComponent* AIPerception;

// Sets default values for this pawn's properties
AAIBasicSensor();

protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;

public:
// Called every frame
virtual void Tick(float DeltaTime) override;

// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

};


Cpp:



// Sets default values
AAIBasicSensor::AAIBasicSensor()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;

AIPerception = CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("AIPerception"));
}


This is the entire code. The error message is:

Does anyone know why this is the case? Thank you.

Forward declare the AIPerceptionComponent class.



UPROPERTY()
class UAIPerceptionComponent* AIPerception;


Also, make sure that you have the proper modules included in your .Build.cs file. I’m not sure which one you need for AI related stuff. You can try these two, and see if it helps.



PublicDependencyModuleNames.AddRange(new string] { "AIModule", "NavigationSystem" });


Thank you, that was the issue! The AIPerceptionComponent works on an AIController without needing AIModule, but it fails on Pawns.