Hello,
I posted this same post on the answer hub, but have not gotten a working response: https://answers.unrealengine.com/questions/509392/uaiperception-onperceptionupdated.html
So I have been working with the perception component but and I have configured a few senses, and then i try to use the OnPerceptionUpdated but the print statement does not work. This is what I have
This is my custom controller class possess function called MobAI:
void AMobAI::Possess(APawn* InPawn) {
Super::Possess(InPawn);
Mob = Cast<AMobCharacter>(InPawn);
SetSenses();
GetPerceptionComponent()->OnPerceptionUpdated.AddDynamic(this, &AMobAI::UpdatePerception);
}
This is the function SetSenses():
void AMobAI::SetSenses() {
Cast<UMobAIPerceptionComponent>(GetPerceptionComponent())->SetSightConfig(Mob);
Cast<UMobAIPerceptionComponent>(GetPerceptionComponent())->SetHearingConfig(Mob);
Cast<UMobAIPerceptionComponent>(GetPerceptionComponent())->SetTouchConfig(Mob);
}
This is the custom PerceptionComponent called MobAIPerceptionComponent:
UMobAIPerceptionComponent::UMobAIPerceptionComponent(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
sightConfig = ObjectInitializer.CreateDefaultSubobject<UMobAISenseConfig_Sight>(this, TEXT("Sight Config"));
hearingConfig = ObjectInitializer.CreateDefaultSubobject<UMobAISenseConfig_Hearing>(this, TEXT("Hearing Config"));
touchConfig = ObjectInitializer.CreateDefaultSubobject<UMobAISenseConfig_Touch>(this, TEXT("Touch Config"));
}
void UMobAIPerceptionComponent::SetSightConfig(AMobCharacter* Mob) {
sightConfig->SetConfig(Mob->Sight, Mob->Sight + (Mob->Sight / 2), 65, true, true, true);
ConfigureSense(*sightConfig);
}
void UMobAIPerceptionComponent::SetHearingConfig(AMobCharacter* Mob) {
hearingConfig->SetConfig(Mob->Hear, true, true, true);
ConfigureSense(*hearingConfig);
}
void UMobAIPerceptionComponent::SetTouchConfig(AMobCharacter* Mob) {
ConfigureSense(*touchConfig);
SetDominantSense(touchConfig->GetSenseImplementation());
}
And finally the custom sense config class (it is essentially the same for all three):
void UMobAISenseConfig_Sight::SetConfig(float Radius, float loseRadius, float VisionAngle, bool detectEnemies, bool detectFreindly, bool detectNuetral) {
SightRadius = Radius;
LoseSightRadius = loseRadius;
PeripheralVisionAngleDegrees = VisionAngle;
DetectionByAffiliation.bDetectEnemies = detectEnemies;
DetectionByAffiliation.bDetectFriendlies = detectFreindly;
DetectionByAffiliation.bDetectNeutrals = detectNuetral;
}
When I use the gameplay debugger (I have actually never used it before, so bear with me) this is what happens:
So with Perception enabled it clearly shows the character is within range of both sight and hearing.
Thank you,