C++ AddDynamic

I am trying to use OnPerceptionUpdated.AddDynamic to update when a pawn is detected, But it wont let me unless i make the array in the function const and with a reference.
the problem is that if i make it that way it wont let me loop on the detected pawns.
If anyone can help me solve this ill be grateful.

The function declaration in the header

    void OnPawnDetected(TArray<AActor*> DetectedPawns);

The cpp add dynamic

PerceptionComponent->OnPerceptionUpdated.AddDynamic(this, &AAI_Zombie_Controller::OnPawnDetected);

The OnPawnDetected function

void AAI_Zombie_Controller::OnPawnDetected(TArray<AActor*> DetectedPawns)
    for (size_t i = 0; i < DetectedPawns.Num; i++)
        DistanceToPlayer = GetPawn()->GetDistanceTo(DetectedPawns*);
    bIsPlayerDetected = true;

The delegate signature for OnPerceptionUpdated is:

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FPerceptionUpdatedDelegate, const TArray<AActor*>&, UpdatedActors);

So it can only be bound to a function that accepts a const ref to an array of AActor*. There’s no way around that part.

But GetDistanceTo accepts a const AActor*, so there should really not be an issue here.

You can also cast away the constness using a const_cast but that’s very rarely the right solution.

Im getting this eror in the loop:
Severity Code Description Project File Line Suppression State
Error C2446 ‘<’: no conversion from ‘int (__cdecl TArray<AActor ,FDefaultAllocator>:: )(void) const’ to ‘size_t’.

how can i fix this?

This has nothing to do with the previous issue. You simply forgot the () after .Num. it should be DetectedPawns.Num()

Thanks you were right