Unable to AddDynamic on AIPerception Component

I am trying to get my head around the AI Perception Component in C++. I’m getting the idea, but I’m stuck at adding a dynamic for the OnPerceptionUpdated event. Every bit of code that I have seen does something like this:

AFPSGuard::AFPSGuard()
    {
     	// ...
    	AIPerceptionComponent->OnPerceptionUpdated.AddDynamic(this, &AFPSGuard::OnSenseUpdated);
    }
    
    void AFPSGuard::OnSenseUpdated(TArray<AActor*> DetectedActors)
    {
          // ...
    }

However, this happens when I do that:

Some solutions I found said that this happens when you don’t use the correct arguments, but every example I have found uses a TArray as the only argument.

I would appreciate any help. I can’t seem to find the problem on my own.

I found this answer earlier: AddDynamic not working with AI Perception Component - AI - Unreal Engine Forums
It says to pass in a TArray, which is what it expects. It is strange, because if I replace the TArray in my code for just TArray, the error goes away. Clearly, though, the engine does not recognize the TArray as it does not specify a type. This kind of makes me think that it could be a bug in the engine version I’m using. I’m not sure, though, which is why I would like to know if something in my code is incorrect.

Nevermind, I found the solution. Seems like in earlier versions you could just pass the array of actors. However, you are now required to pass in a constant reference to the array. So the function should look like this:

void AFPSGuard::OnSenseUpdated(const TArray<AActor*>& DetectedActors)
{
      // ...
}

Also, in case it helps anyone, don’t forget that you need to add to declare the method with UFUNCTION() on top, or else it won’t compile:

UFUNCTION() 
void OnSenseUpdated(const TArray<AActor*>& DetectedActors);