Adding AIPerceptionComponent causes compilation error

Hi All

I’ve been trying to do a boid simulation and as part of it included AIPerceptionComponent to an actor. But just by including that, the compilation keeps failing for a reason unknown to me.

To ensure it is not something to do with the project, I created another project with First Person C++ template and added the same to Character.h and Character.cpp and I got the same compilation error.

All I did was adding below to Character.h
*UPROPERTY(VisibleDefaultsOnly, Category = AI)
class UAIPerceptionComponent
PerceptionComp;

**

And below header to the CPP
#include "Perception/AIPerceptionComponent.h"

And below code under the constructor of the CPP
PerceptionComp**= CreateDefaultSubobject<UAIPerceptionComponent>(TEXT(“AIPerception”));**

The error, which is something about an unsolved external symbol

Does anyone know what is going on here?

Thank you

Did you add AIModule to your public dependency list? In your {ProjectName}.Build.cs, add it to the PublicDependencyModuleNames. Something like this:


PublicDependencyModuleNames.AddRange(new string] { "Core", "CoreUObject", "Engine", "InputCore", "AIModule" });

Thanks @UnrealXinda, It fixed the problem. I didn’t even know about it and It looks like a bit of a gotcha! I will look it up further. I was following the AI Blueprint tutorial and was trying to do it in C++. Thanks again!