How to set up AI Perception hearing sense?


Can someone please tell me how to set up AI perception hearing sense in C++. I’ve already have sight set up, but somehow I can’t get to make actors be perceived through hearing.

This is what I’m doing now:

  1. AIController constructor:

    SetPerceptionComponent(*ObjectInitializer.CreateDefaultSubobject(this, TEXT(“Perception”)));
    GetAIPerceptionComponent()->OnPerceptionUpdated.AddDynamic(this, &ACritterAIController::OnPerceptionUpdated);

  2. AIController::Possess

    ACritter* critter = Cast(GetPawn());
    for (UAISenseConfig* config : critter->SensesConfig){

  3. AActor::BeginPlay

    UAIPerceptionSystem::RegisterPerceptionStimuliSource(this, UAISense_Sight::StaticClass(), this);
    UAIPerceptionSystem::RegisterPerceptionStimuliSource(this, UAISense_Hearing::StaticClass(), this);

  4. This is what I use to make a noise from within AActor class:

    UAISense_Hearing::ReportNoiseEvent(this, GetActorLocation(), 1.0, this);

  5. And this is my config of senses in AActor blueprint:

Any help is much appreciated!

It seems that when I move sense configuration from AAIController::Possess to AAIController constructor then everything works perfectly. This seems like a potentional bug. Can someone comment on this?

I had a problem along similar lines that might help. I was constructing and configuring the sense of an AI’s AIPerceptionComponent in their constructor and this worked well for a while but for some reason after a while trying to change the variables for the (sight) perception range or angles in editor between play sessions wouldn’t make any difference, they were stuck in an old setting for some reason. The variables were applied to the sense config in the constructor at this point.
After a day of banging my head against the problem I tried moving the configuration to BeginPlay, but keeping the construction of the AIPerceptionComponent and UAISenseConfig_Sight in the object constructor. That seemed to override any old settings that the engine seemed intent on enforcing.
So I think the component settings and state get altered sometime between construction and BeginPlay. Perhaps there’s a similar ordering problem with Possess?

Sidenote: sorry about the formatting, looks like comments don’t make use of new lines.

I ran into a very similar issue. Updates to the child could never deviate from the parent. I had to delete and replace all the components to remedy the issue. Probably an editor bug