Hi Unreal experts,
I have a custom AI controller I am working on, which handles sight & sound perception. Here is the code in the AI controller’s constructor, that sets this up:
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
// Setup the sight config
sightConfig = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("Sight Config"));
sightConfig->SightRadius = 3000;
sightConfig->LoseSightRadius = (sightConfig->SightRadius + 20);
sightConfig->PeripheralVisionAngleDegrees = 180.f;
sightConfig->DetectionByAffiliation.bDetectEnemies = true;
sightConfig->DetectionByAffiliation.bDetectNeutrals = true;
sightConfig->DetectionByAffiliation.bDetectFriendlies = true;
// Setup the hearing config
hearingConfig = CreateDefaultSubobject<UAISenseConfig_Hearing>(TEXT("Hearing Config"));
hearingConfig->HearingRange = 3000;
hearingConfig->DetectionByAffiliation.bDetectEnemies = true;
hearingConfig->DetectionByAffiliation.bDetectNeutrals = true;
hearingConfig->DetectionByAffiliation.bDetectFriendlies = true;
// Setup the perception component
perceptionComponent = CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("AIPerception Component"));
perceptionComponent->OnPerceptionUpdated.AddDynamic(this, &AMerlinAIController::OnPerceptionUpdated);
perceptionComponent->ConfigureSense(*sightConfig);
perceptionComponent->ConfigureSense(*hearingConfig);
perceptionComponent->SetDominantSense(sightConfig->GetSenseImplementation());
I have two BP actors, one that represents something visual (which has a sight-stimuli source component), and one that represents a sound (which has a hearing-stimuli source component), configured as follows, respectively:
When running the game in the editor, I can press ’ and then 4 to validate that the NPC can see the actor with visual stimuli-source (I get the green sphere around it), but I do NOT get a yellow sphere around the actor with the hearing-stimuli-source on it.
However, if I add a ReportNoiseEvent and set it to the location of the actor with hearing-stimuli-source, the NPC does “hear” it and generates a yellow sphere around the location of the noise-event.
Question 1: Am I supposed to use ReportNoiseEvent or hearing-stimuli-source? If both, then why is there no ReportSightEvent? And why even bother with stimuli-sources? It seems like there is ambiguous overlap between the event vs stimuli-source design here, or what am I missing?
Question 2: Sounds fade out over time, so how do I control the ‘max age’ of a sound?
(I am not talking about the sound the player hears - e.g. not fading out audio volume - instead I’m concerned with destroying the ‘sound actor or component’).
Based on what I have learned about Unreal so far (I am only a week into this), I can guess at any of the following:
a) I make custom age & maxAge properties on the actor with the stimuli-source/event/whatever and use a tick function to manually increment that age property, and when it reaches the maxAge I de-spawn/destroy the actor.
b) I could try to use the maxAge on the PerceptionComponent, but I don’t see how it would work? Why would a maxAge be on the listener? It is not the listener that fades out - it is the source / the sound itself.
I think I am not understanding the intent & design of all this, so any help is greatly appreciated!
Marcus