Download

Pawn sensing component

How do i add a pawn sensing component properly in c++?
I tryed this but i get an error:

Error LNK2019 unresolved external symbol “__declspec(dllimport) class UClass * __cdecl Z_Construct_UClass_UPawnSensingComponent_NoRegister(void)” (_imp?Z_Construct_UClass_UPawnSensingComponent_NoRegister@@YAPEAVUClass@@XZ) referenced in function “void __cdecl `dynamic initializer for ‘public: static struct UE4CodeGen_Private::FObjectPropertyParams const Z_Construct_UClass_APirate_Statics::NewProp_PawnSensing’’(void)” (??__E?NewProp_PawnSensing@Z_Construct_UClass_APirate_Statics@@2UFObjectPropertyParams@UE4CodeGen_Private@@B@@YAXXZ) Pirates D:\Unreal Engine 4\Unreal Projects\Pirates\Intermediate\ProjectFiles\Pirate.gen.cpp.obj

.h



#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Pirate.generated.h"

class UPawnSensingComponent;

UCLASS()
class PIRATES_API APirate : public ACharacter
{
    GENERATED_BODY()

public:
    // Sets default values for this character's properties
    APirate();

protected:

    UPROPERTY(VisibleDefaultsOnly, Category = "Components")
        UPawnSensingComponent* PawnSensing;

    UFUNCTION()
        void SeePawn(APawn* Pawn);

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

};



.cpp



#include "Pirate.h"
#include "Perception/PawnSensingComponent.h"

// Sets default values
APirate::APirate()
{
    PawnSensing = CreateDefaultSubobject<UPawnSensingComponent>(TEXT("PawnSensing"));
}

void APirate::SeePawn(APawn* Pawn)
{
        //nothing... yet
}

void APirate::BeginPlay()
{
    Super::BeginPlay();

    PawnSensing->OnSeePawn.AddDynamic(this, &APirate::SeePawn);
}


I tryed commenting some lines to locate the error. It seems like commenting the declaration solves the error. I guess i misdeclared something?

I found out that declaring the UPawnSensingComponent as a UPROPERTY() causes the error. How should i declare it than to expose its defaults to blueprints?