Hi,
I looked around and found a couple really useful threads about how to set up AI Perception in c++. The one thing im getting stuck on however is creating my own function to get called with OnPerceptionUpdated. What I have now has no errors it just isn’t calling my debug message when I enter into my AI’s sight perception. So I assume that My SenseUpdated function is not being called when you would expect it should be.
Heres the .h
UCLASS()
class PW_GAME_API APWAIController : public AAIController
{
GENERATED_BODY()
APWAIController(const FObjectInitializer& ObjectInitializer);
UAISenseConfig_Sight* sightConfig;
TScriptDelegate<> sense;
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AI")
float agroRange;
UFUNCTION(Category = "Perception")
void SenseUpdated(TArray<AActor*>& testActors);
};
and heres the .cpp
APWAIController::APWAIController(const FObjectInitializer& ObjectInitializer)
:Super(ObjectInitializer.SetDefaultSubobjectClass<UPWPathFollowingComponent>(TEXT("PathFollowingComponent")))
{
agroRange = 500;
PerceptionComponent = CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("Perception Component"));
sightConfig = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("Sight Config"));
PerceptionComponent->ConfigureSense(*sightConfig);
PerceptionComponent->SetDominantSense(sightConfig->GetSenseImplementation());
sightConfig->SightRadius = agroRange;
sightConfig->LoseSightRadius = agroRange + 50;
sightConfig->DetectionByAffiliation.bDetectEnemies = true;
sightConfig->DetectionByAffiliation.bDetectNeutrals = true;
sightConfig->DetectionByAffiliation.bDetectFriendlies = true;
sense.BindUFunction(this,"SenseUpdated");
PerceptionComponent->OnPerceptionUpdated.Add(sense);
}
void APWAIController::SenseUpdated(TArray<AActor*>& Actors)
{
GEngine->AddOnScreenDebugMessage(-1, 10, FColor::Blue, "Perception Sense Updated");
}