I was implementing UAIPerceptionComponent
on a Player Controller. I am starting only with a sight sense. To make iterations time faster, I have a blueprint derived from my C++ Player Controller, in which I can set variables like SightRadius
and LoseSightRadius
. Because I instantiate that blueprint class, I have to register sight in Begin Play. This was my initial setup:
MyPlayerController.h
public:
UPROPERTY()
UAIPerceptionComponent* AIPerceptionComponent;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
UAISenseConfig_Sight* SightConfig;
MyPlayerController.cpp : Constructor
AIPerceptionComponent = CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("PerceptionComponent"));
SetPerceptionComponent(*AIPerceptionComponent);
SightConfig = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("SightConfig"));
MyPlayerController.cpp : BeginPlay
Super::BeginPlay();
if (SightConfig && AIPerceptionComponent){
//Do stuff
} else {
UE_LOG(LogTemp, Warning, TEXT("Not configuring sense"));
}
Every time I got the warning Not configuring sense
. After hours of debugging and even reinstalling the engine, I found that SightConfig
was assigned successfully on the constructor, but was set to 0x0 (NULL), after, by the engine, in a call to FObjectInitializer
to my Blueprint Class, concretely on PostConstructInit
. UAISenseConfig_Sight
inherits from UObject
, so I assumed it would be safe to have a member pointer with UPROPERTY
.
After changing
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
UAISenseConfig_Sight* SightConfig;
to
UPROPERTY(VisibleAnywhere)
UAISenseConfig_Sight* SightConfig;
everything started to work as it should. Why does this happen? Is there any explanation?
Thanks