Access violation when using AI Hearing Perception [C++]

Mr.Pathetic
Mon, 25 Nov 2019 05:09:39 +0000
AI

I’m trying to use the AI Perception component but I’m getting a seemingly random error when trying to access my USenseConfig_Hearing object.

This is my code:

AHumanAIController:AHumanAIController()
{
    AIPerceptionComponent = CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("PerceptionComponent"));

    HearingConfig = CreateDefaultSubobject<UAISenseConfig_Hearing>(TEXT("HearingConfig"));

    AIPerceptionComponent->ConfigureSense(*HearingConfig);
}

AHumanAIController::BeginPlay()
{
    Super::BeginPlay();

    AIPerceptionComponent->OnTargetPerceptionUpdated.AddDynamic(this, &AHumanAIController::HandleTargetPerceptionUpdated);
}

void AHumanAIController::HandleTargetPerceptionUpdate(AActor* Actor, FAIStimulus Stimulus)
{
    if(Stimulus.Type == HearingConfig->GetSenseID()) // Exception here
    {
        // Do stuff
    }
}

The exception is an access violation exception and it looks like the HearingConfig pointer is pointing to garbage memory. However, I really don’t understand how this is happening given that it’s seemingly at random. The Ai that’s using this controller can hear the player perfectly for some time, but after the player runs around the AI character for a while (making noise while running), the exception is triggered.

I would really appreciate any help with this issue, since I’m starting to think it is a bug in the engine. I hope I’m wrong and it’s just that there’s something in my code that I haven’t realized is wrong. Any help would be greatly appreciated.

EDIT: I’m probably wrong when I say that it’s pointing at garbage memory. I’ll add the screenshots.
This is the exception:

And then this is the value of HearingConfig, which seems to be correct except for the Name being “None”:

5 posts - 3 participants