How do you create a delegate to add to PerceptionComponent->OnPerceptionUpdated

I Fixed it, kinda silly however I shall post the answer all the same. I did not realize that AddDynamic was a macro and my Intellesense was not showing it therefore I did not think It existed. Once I figured out I could use it, it made things really easy. here’s the updated code (Just the cpp):

APWAIController::APWAIController(const FObjectInitializer& ObjectInitializer)
	:Super(ObjectInitializer.SetDefaultSubobjectClass<UPWPathFollowingComponent>(TEXT("PW PathFollowingComponent")))
{
	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;

	PerceptionComponent->OnPerceptionUpdated.AddDynamic(this, &APWAIController::SenseUpdated);
}

void APWAIController::SenseUpdated(TArray<AActor*> Actors)
{
	GEngine->AddOnScreenDebugMessage(-1, 10, FColor::Blue, "Perception Sense Updated");
}
1 Like