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

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”:

First let’s handle your crashing issue.

if (HearingConfig)
{
     if(Stimulus.Type == HearingConfig->GetSenseID()) // Exception here
     {
         // Do stuff
     }
}

After we fix the crashing issue, check if it fixes, if not, you should add some debug messages to see whose calling the function.

Hey, thanks for the answer. This does not fix the issue, though. HearingConfig is never set to NULL, it just randomly starts pointing at garbage memory, so the if check will still be true when it’s not a valid pointer.

Could you please elaborate on what you mean by adding the debug messages? Since it’s a dynamic method called on the OnTargetPerceptionUpdated event, I wouldn’t know how to do that.

Wait, no. I’m lying, I’m not even sure HearingConfig is pointing to garbage memory. I’ve edited the original questions to show pictures of the error.