Download

OnPerceptionUpdated.AddDynamic no instance of function template matches the argument list.

I recently upgraded to UE4.22 and now i am getting an error in my code. The error comes from the the line:
GetPerceptionComponent()->OnPerceptionUpdated.AddDynamic(this, &AAIController_Wolf::OnPawnDetected);

Now i am getting the error “no instance of function template matches the argument list.”. I cannot figure out what is going on.

// Fill out your copyright notice in the Description page of Project Settings.

#include “AIController_Wolf.h”
#include “Character_Wolf.h”
#include “Perception/AIPerceptionComponent.h”
#include “Perception/AISenseConfig_Sight.h”

//Constructor
AAIController_Wolf::AAIController_Wolf()
{

}

void AAIController_Wolf::BeginPlay()
{
Super::BeginPlay();
if (GetAIPerceptionComponent() != nullptr)
{

    UE_LOG(LogTemp, Warning, TEXT("All Systems Set"));
}
else
{
    UE_LOG(LogTemp, Warning, TEXT("Error setting perception component"));

}

}

/*void AAIController_Wolf::Possess(APawn * Pawn)
{
Super::Possess(Pawn);
}
/
void AAIController_Wolf::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
FVector targetLocation;
ACharacter_Wolf
character = Cast<ACharacter_Wolf>(GetPawn());

if (target != NULL)
{
    targetLocation = GetTargetLocation(target);
}
else
{
    emenyDetected = false;
}

if (emenyDetected)
{
    //Get the direction this controller is facing
    FVector focalPoint = GetFocalPoint();

    //Subtract that direction from the targets location
    FVector direction = focalPoint - targetLocation;

    //Save this direction in a rotation variable
    FRotator newRotation = direction.Rotation();

    //clamp the angle so it is a valid angle
    newRotation.Yaw = FRotator::ClampAxis(newRotation.Yaw);

    SetControlRotation(newRotation);

    character-&gt;FaceRotation(newRotation, DeltaSeconds);
}

}

FRotator AAIController_Wolf::GetControlRotation() const
{
if (GetPawn() == nullptr)
{
return FRotator(0.0f, 0.0f, 0.0f);
}
//Yaw is rotation around the up axis (around Z axis), Running in circles 0=East, +North, -South.
return FRotator(0.0f, GetPawn()->GetActorRotation().Yaw, 0.0f);
}

void AAIController_Wolf::OnPawnDetected(TArray<AActor*> Detectedpawns)
{

emenyDetected = true;
target = Detectedpawns[0];
PrimaryActorTick.bCanEverTick = true;

SightConfig = CreateDefaultSubobject&lt;UAISenseConfig_Sight&gt;(TEXT("Sight Config"));
SetPerceptionComponent(*CreateDefaultSubobject&lt;UAIPerceptionComponent&gt;(TEXT("Perception Component")));
//PerceptionComponent = CreateDefaultSubobject&lt;UAIPerceptionComponent&gt;(TEXT("Perception Component"));


//Sets how far we can see, when we lose sight, the angle at which we can see, and how long we can see
SightConfig-&gt;SightRadius = AISightRadius;
SightConfig-&gt;LoseSightRadius = AILoseSightRadius;
SightConfig-&gt;PeripheralVisionAngleDegrees = AIFieldOfView;
SightConfig-&gt;SetMaxAge(AISightAge);

//we can detect, by affliliation, friendles, enemies, and neutrals. 
SightConfig-&gt;DetectionByAffiliation.bDetectEnemies = false;
SightConfig-&gt;DetectionByAffiliation.bDetectFriendlies = false;
SightConfig-&gt;DetectionByAffiliation.bDetectNeutrals = false;

//Set the dominant sense as sight
GetPerceptionComponent()-&gt;SetDominantSense(*SightConfig-&gt;GetSenseImplementation());
GetPerceptionComponent()-&gt;OnPerceptionUpdated.AddDynamic(this, &AAIController_Wolf::OnPawnDetected);
GetPerceptionComponent()-&gt;ConfigureSense(*SightConfig);

}

This sounds familiar…

A quick look at the delegate :


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

Your parameter is just a TArray.
The delegates is a a const TArray.
Guessing that is the change :slight_smile: