AI Perception Sight - not running, no debug visible

I’m trying to build some AI based on AIPerception Sight Sense. I’ve followed this one, but it seems that the OnPerceptionUpdated doesn’t get called. Also the debug isn’t being drawn at all. Is there any bug on this right now?

Constuctor:

AIPerceptionComp = CreateDefaultSubobject<UAIPerceptionComponent>( TEXT("AIPerceptionComponent") );
AISenseConfig_Sight = CreateDefaultSubobject<UAISenseConfig_Sight>( TEXT("SenseConfig Sight"));
AIPerceptionComp->ConfigureSense( *AISenseConfig_Sight );
AIPerceptionComp->SetDominantSense( AISenseConfig_Sight->GetSenseImplementation() );
AIPerceptionComp->OnPerceptionUpdated.AddDynamic(this, &ALobberCharacter::UpdatePerception);
AIPerceptionComp->Activate();

My function:

void ALobberCharacter::UpdatePerception(TArray<AActor*> ActorsPercepted)
{
    UE_LOG(LogTemp, Warning, TEXT("UPDATE PERCEPTION"));
     GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Red, TEXT("UPDATE PERCEPTION"));
}

I also put this on player’s and other pawns constructor:

UAIPerceptionSystem::RegisterPerceptionStimuliSource(this, AISenseConfig_Sight->GetSenseImplementation(), GetController() );

The blueprint’s config is pretty default on that, everything should work then. Help very appreciated.

Hey Krzsiek_Tate,

I answered a similar question before I think this also might be your problem :slight_smile:

Hope it helps,
Elias

Hey -

The DetectionByAffiliation settings for your AISenseConfig_Sight need to be set to true for the perception component to work properly. Please check out the answer for the following post for a quick explanation of how to setup the perception component and sense config: UAIPerception OnPerceptionUpdated not working - AI - Epic Developer Community Forums

Cheers

It’s not a case I think. The default values are all set to true. And I actualy tried this also before.

You seem to be right. I’ve moved the code to AIController, but the OnPerceptionUpdated is not been called afterall. I see the debugging for the perception on Gameplay Debugger. I’ve registered the player and other pawns with RegisterPerceptionStimuliSource. It should work… but it’s not.

hmm, make sure your UpdatePerception() a UFUNTION.

also for each sense set their DetectionByAffiliation, example:

sightConfig->DetectionByAffiliation.bDetectEnemies = true;
sightConfig->DetectionByAffiliation.bDetectNeutrals = true;
sightConfig->DetectionByAffiliation.bDetectFriendlies = true;

edit: I just your comment on 's answer so yea it should work, I also saw some problems if you put the PeripheralVisionAngleDegrees to 360.0f; try to put it around 90 to test properly.

It’s fixed now. After the nearest Unreal restart in time it started to work -_- I hate when UE is doing that.

1 Like

Ok. Now I’ve found a real reason why everything wasn’t working after moving stuff to AIController and making some changes in it. I’ve found an in engine bug