Can you fix UStateTreeAIComponent to be inherited in c++?

UStateTreeComponent works perfectly fine, with all modules included, but not UStateTreeAIComponent, it will give this error:

0>Module.PossessionGame.1.cpp.obj: Error : LNK2019: unresolved external symbol “private: static class UClass * __cdecl UStateTreeAIComponent::GetPrivateStaticClass(void)” (?GetPrivateStaticClass@UStateTreeAIComponent@@CAPEAVUClass@@XZ) referenced in function “public: static class UClass * __cdecl UStateTreeAIComponent::StaticClass(void)” (?StaticClass@UStateTreeAIComponent@@SAPEAVUClass@@XZ)
0>Module.PossessionGame.1.cpp.obj: Error : LNK2019: unresolved external symbol “public: __cdecl UStateTreeAIComponent::UStateTreeAIComponent(class FObjectInitializer const &)” (??0UStateTreeAIComponent@@QEAA@AEBVFObjectInitializer@@@Z) referenced in function “public: __cdecl UCustomStateTreeAIComponent::UCustomStateTreeAIComponent(class FObjectInitializer const &)” (??0UCustomStateTreeAIComponent@@QEAA@AEBVFObjectInitializer@@@Z)
0>Module.PossessionGame.1.cpp.obj: Error : LNK2019: unresolved external symbol “public: __cdecl UStateTreeAIComponent::UStateTreeAIComponent(class FVTableHelper &)” (??0UStateTreeAIComponent@@QEAA@AEAVFVTableHelper@@@Z) referenced in function “public: __cdecl UCustomStateTreeAIComponent::UCustomStateTreeAIComponent(class FVTableHelper &)” (??0UCustomStateTreeAIComponent@@QEAA@AEAVFVTableHelper@@@Z)
0>Module.PossessionGame.1.cpp.obj: Error : LNK2019: unresolved external symbol “public: virtual __cdecl UStateTreeAIComponent::~UStateTreeAIComponent(void)” (??1UStateTreeAIComponent@@UEAA@XZ) referenced in function “public: virtual __cdecl UCustomStateTreeAIComponent::~UCustomStateTreeAIComponent(void)” (??1UCustomStateTreeAIComponent@@UEAA@XZ)
0>Module.PossessionGame.1.cpp.obj: Error : LNK2001: unresolved external symbol "public: virtual class TSubclassOf __cdecl UStateTreeAIComponent::GetSchema(void)const " (?GetSchema@UStateTreeAIComponent@@UEBA?AV?$TSubclassOf@VUStateTreeSchema@@@@XZ)
0>Module.PossessionGame.1.cpp.obj: Error : LNK2001: unresolved external symbol “public: virtual bool __cdecl UStateTreeAIComponent::SetContextRequirements(struct FStateTreeExecutionContext &,bool)” (?SetContextRequirements@UStateTreeAIComponent@@UEAA_NAEAUFStateTreeExecutionContext@@_N@Z)
0>UnrealEditor-PossessionGame.dll: Error : LNK1120: 6 unresolved externals

The issue is that the UStateTreeAIComponent isn’t API exposed. If you are building the engine, you need to add GAMEPLAYSTATETREEMODULE_API to StateTreeAIComponent.h like so

class GAMEPLAYSTATETREEMODULE_API UStateTreeAIComponent : public UStateTreeComponent

You have a linker error

Make sure your build file includes the module

GameplayStateTreeModule

it is also dependent on “AIModule” because internally it references UBrainComponent
in your public dependencies

You also need to include the following header either in your header file or forward declare the component and put the include in your cpp file (a better option)

#include "Components/StateTreeAIComponent.h"

Successful compile below: