Hey everyone,
I think I found a bug with the AI Perception system. I have an AI Pawn set up to use sight. When leaving the outer lose sight radius, my perception isn’t updated to inform my AI Controller that the sight has been lost:
void AEnemyAIController::OnTargetPerceptionUpdated(AActor* Actor, FAIStimulus Stimulus)
{
GEngine->AddOnScreenDebugMessage(-1, 2, FColor::White, FString::Printf(TEXT("Target %s perception updated!"), *Actor->GetName()));
if(Stimulus.WasSuccessfullySensed())
{
GEngine->AddOnScreenDebugMessage(-1, 2, FColor::Cyan, FString::Printf(TEXT("Target %s sensed!"), *Actor->GetName()));
SetEnemy(Cast<ASpaceShip>(Actor));
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 2, FColor::Cyan, TEXT("Target lost..."));
SetEnemy(nullptr);
}
}
I’m only receiving one call to the update method when the player is sensed. This was working in the past. Not sure when but I guess around UE 4.17. I’m registering the method in begin play:
void AEnemyAIController::BeginPlay()
{
Super::BeginPlay();
UAIPerceptionComponent* perceptionComponent = GetPerceptionComponent();
if (ensureMsgf(perceptionComponent, TEXT("Perception component not set, cannot intialize target perception updating")))
{
perceptionComponent->OnTargetPerceptionUpdated.AddDynamic(this, &AEnemyAIController::OnTargetPerceptionUpdated);
}
}
I also recorded a video showing how the AI never loses sight of me: UE 4.19 - AI Perception sight is never lost - YouTube
Is this a bug or did something change and I’m doing it wrong now?