# AddDynamic not working with OnPerceptionUpdated

**URL:** <https://forums.unrealengine.com/t/adddynamic-not-working-with-onperceptionupdated/483686>\
**Category:** C++\
**Tags:** aiperception, c-build-fail, unreal-engine, question, CPP\
**Created:** [May 20, 2021, 10:22pm UTC](https://forums.unrealengine.com/t/adddynamic-not-working-with-onperceptionupdated/483686 "2021-05-20T22:22:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![M.AbdullahSultan](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/m.abdullahsultan/32/564057_2.png) [@M.AbdullahSultan](https://forums.unrealengine.com/u/M.AbdullahSultan)\
**Post date:** [May 20, 2021, 10:22pm UTC](https://forums.unrealengine.com/t/adddynamic-not-working-with-onperceptionupdated/483686/1 "2021-05-20T22:22:54Z")

</div>

## Add dynamic is not working with OnPerceptionUpdated, it throws weird build error I can’t figure out

Kindly point out problem and suggest solution

### The .h File:
   

```
#pragma once

#include "CoreMinimal.h"
#include "AIController.h"
#include "ZombieAIController.generated.h"

class UAISenseConfig_Sight;
class UAISenseConfig_Hearing;
class UAIPerceptionComponent;

/**
 * 
 */
UCLASS()
class MYPROJECT_API AZombieAIController : public AAIController
{
	GENERATED_BODY()

	AZombieAIController();
	void BeginPlay() override;

public:
	UAIPerceptionComponent* AIPerceptioComponent;
	UAISenseConfig_Sight* Sense_Sight;
	UAISenseConfig_Hearing* Sense_Hearing;

	UFUNCTION()
	void OnPlayerDetected(TArray<AActor*>DetectedPawn);
};

```

  

### The .cpp file
   

```
#include "ZombieAIController.h"
#include "Perception/AIPerceptionComponent.h"
#include "Perception/AISenseConfig_Sight.h"
#include "Perception/AISenseConfig_Hearing.h"

AZombieAIController::AZombieAIController()
{
	PrimaryActorTick.bCanEverTick = false;

	Sense_Sight = CreateDefaultSubobject<UAISenseConfig_Sight>(FName("Sense_Sight"));
	Sense_Hearing = CreateDefaultSubobject<UAISenseConfig_Hearing>(FName("Sense_Hearing"));
	AIPerceptioComponent = CreateDefaultSubobject<UAIPerceptionComponent>(FName("AIPerceptioComponent"));

	Sense_Sight->SightRadius = 3000;
	Sense_Sight->LoseSightRadius = 3500;
	Sense_Sight->PeripheralVisionAngleDegrees = 180;
	Sense_Sight->DetectionByAffiliation.bDetectEnemies = true;
	Sense_Sight->DetectionByAffiliation.bDetectFriendlies = true;
	Sense_Sight->DetectionByAffiliation.bDetectNeutrals = true;
	Sense_Sight->AutoSuccessRangeFromLastSeenLocation = 1500;

	Sense_Hearing->HearingRange = 3000;
	AIPerceptioComponent->ConfigureSense(*Sense_Sight);
	AIPerceptioComponent->ConfigureSense(*Sense_Hearing);

	AIPerceptioComponent->OnPerceptionUpdated.AddDynamic(this, &AZombieAIController::OnPlayerDetected);
}

void AZombieAIController::BeginPlay() {
	Super::BeginPlay();
}

void AZombieAIController::OnPlayerDetected(TArray<AActor*>DetectedPawn)
{
}

```

  

### VS error Log

```
>F:\New folder\MyProject\Source\MyProject\ZombieAIController.cpp(29): error C2664: 'void TBaseDynamicMulticastDelegate<FWeakObjectPtr,void,const TArray<AActor *,FDefaultAllocator> &>::__Internal_AddDynamic<AZombieAIController>(UserClass *,void (__cdecl AZombieAIController::* )(const TArray<AActor *,FDefaultAllocator> &),FName)': cannot convert argument 2 from 'void (__cdecl AZombieAIController::* )(TArray<AActor *,FDefaultAllocator>)' to 'void (__cdecl AZombieAIController::* )(const TArray<AActor *,FDefaultAllocator> &)'
1> with
1> [
1> UserClass=AZombieAIController
1> ]
1> F:\New folder\MyProject\Source\MyProject\ZombieAIController.cpp(29): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1> C:\Program Files\Epic Games\UE_4.26\Engine\Source\Runtime\Core\Public\Delegates/DelegateSignatureImpl.inl(1101): note: see declaration of 'TBaseDynamicMulticastDelegate<FWeakObjectPtr,void,const TArray<AActor *,FDefaultAllocator> &>::__Internal_AddDynamic'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.MakeFile.Targets(46,5): error MSB3073: The command ""C:\Program Files\Epic Games\UE_4.26\Engine\Build\BatchFiles\Build.bat" MyProjectEditor Win64 Development -Project="F:\New folder\MyProject\MyProject.uproject" -WaitMutex -FromMsBuild" exited with code 6.
1>Done building project "MyProject.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

```

  

### UE4 Error log

```
   F:\New folder\MyProject\Source\MyProject\ZombieAIController.cpp(36) : error C2664: 'void TBaseDynamicMulticastDelegate<FWeakObjectPtr,void,const TArray<AActor *,FDefaultAllocator> &>::__Internal_AddDynamic<AZombieAIController>(UserClass *,void (__cdecl AZombieAIController::* )(const TArray<AActor *,FDefaultAllocator> &),FName)': cannot convert argument 2 from 'void (__cdecl AZombieAIController::* )(TArray<AActor *,FDefaultAllocator>)' to 'void (__cdecl AZombieAIController::* )(const TArray<AActor *,FDefaultAllocator> &)'
          with
          [
          ]
              UserClass=AZombieAIController

```

---

<div class="post-metadata">

**Author:** ![Kehel18](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kehel18](https://forums.unrealengine.com/u/Kehel18)\
**Post date:** [May 21, 2021, 3:38pm UTC](https://forums.unrealengine.com/t/adddynamic-not-working-with-onperceptionupdated/483686/2 "2021-05-21T15:38:03Z")

</div>

Hello! Your signature for method is incorrect, just take a look at defenition

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

---

<div class="post-metadata">

**Author:** ![M.AbdullahSultan](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/m.abdullahsultan/32/564057_2.png) [@M.AbdullahSultan](https://forums.unrealengine.com/u/M.AbdullahSultan)\
**Post date:** [May 21, 2021, 4:48pm UTC](https://forums.unrealengine.com/t/adddynamic-not-working-with-onperceptionupdated/483686/3 "2021-05-21T16:48:31Z")

</div>

**The problem was with function parameters that was to be called OnPerceptionUpdated, they should be as follows:**

```
UFUNCTION()
	void OnPlayerDetected(const TArray<AActor*>&DetectedPawn);
```
