How to initialize and attach UActor Components in C++

Right now my code looks like this.

// Header
class UPawnSensingComponent* PawnSensor;

// This compiles fine until I add the below in the CPP

PawnSensor = CreateDefaultSubobject<UPawnSensingComponent>(TEXT("PawnSensor"));

It keeps giving me unresolved externals errors which makes me think there is some other step I am missing, but I can’t for the life of me find it. At first I thought I needed to use SetupAttachment, but no such definition exists within the UPawnSensingComponent.

Does anyone know what I can do?

I guess that missing add dependency.

open [Project].Build.cs file, and search “AIModule” inside of PublicDependencyModuleNames (like, “Core”, “Engine”, “AIModule” …), if “AIModule” not exists, add it. I hope it works.

Thanks. Also had to include the Perception/PawnSensingComponent.h, but it worked!