OnOverlap AddDynamic error C2664

Parameter was Added you miss one if you are using 4.12

for versions bellow 4.12 use

  UFUNCTION()
  void OnOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
      
  UFUNCTION()
  void OnHit(class AActor* act, class UPrimitiveComponent* Other, FVector Impulse, const FHitResult & HitResult);

for 4.12 and above

  UFUNCTION()
  void OnOverlap(class UPrimitiveComponent* OverlappingComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
      
  UFUNCTION()
  void OnHit(class UPrimitiveComponent* HitComp, class AActor* Actor, class UPrimitiveComponent* Other, FVector Impulse, const FHitResult & HitResult);

Good Luck and have Fun =)

Hi all,

I’ve been following this tutorial, updating the outdated parts as I go along and deleting the parts I don’t think I need. This is a simplified version of my header file:

#pragma once

#include "GameFramework/Actor.h"
#include "MyActor.generated.h"

UCLASS()
class MYPROJECT4_API AMyActor : public AActor
{
	GENERATED_UCLASS_BODY()

		UPROPERTY(VisibleDefaultsOnly, Category = Projectile)
		USphereComponent* CollisionComponent;

	UFUNCTION()
		void OnOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

	UFUNCTION()
		void OnEndOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);

public:
	AMyActor();

	virtual void BeginPlay() override;

	virtual void Tick(float DeltaSeconds) override;

	float RunningTime;
	virtual void NotifyHit(UPrimitiveComponent* MyComp, AActor* Other, UPrimitiveComponent* OtherComp, bool BSelfMoved, FVector HitLocation, FVector HitNormal, FVector NormalImpulse, const FHitResult& Hit) override;
};

and a simplified version of my cpp

#include "MyProject4.h"
#include "MyActor.h"

AMyActor::AMyActor(const class FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	PrimaryActorTick.bCanEverTick = true;

	CollisionComponent = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("SphereComp"));
	CollisionComponent->InitSphereRadius(50.f);
	OnActorBeginOverlap.AddDynamic(this, &AMyActor::OnOverlap);
	OnActorEndOverlap.AddDynamic(this, &AMyActor::OnEndOverlap);
	RootComponent = CollisionComponent;
}

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

// Called every frame
void AMyActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	//Define new atom position
	FVector NewLocation = GetActorLocation();
	SetActorLocation(GetActorLocation() + MyVelocity * DeltaTime, true);
}

void AMyActor::OnOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (OtherActor != this)
{
	GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::Green, ("Do the thing"));
}

void AMyActor::OnEndOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
	GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::Green, ("Ok, don't do the thing"));
}

void AMyActor::NotifyHit(UPrimitiveComponent* MyComp, AActor* Other, UPrimitiveComponent* OtherComp, bool bSelfMoved, FVector HitLocation, FVector HitNormal, FVector NormalImpulse, const FHitResult& Hit)
{
	Super::NotifyHit(MyComp, Other, OtherComp, bSelfMoved, HitLocation, HitNormal, NormalImpulse, Hit);
	FVector ReflectedVelocity = (-2 * FVector::DotProduct(MyVelocity, HitNormal) * HitNormal + MyVelocity);
	MyVelocity = ReflectedVelocity;
	ReflectedVelocity.Normalize();
}

This keeps giving me the following pesky error for OnOverlap and OnEndOverlap

Error	C2664	'void TBaseDynamicMulticastDelegate<FWeakObjectPtr,void,AActor *>::__Internal_AddDynamic<AMyActor>(UserClass *,void (__cdecl AMyActor::* )(AActor *),FName)': cannot convert argument 2 from 'void (__cdecl AMyActor::* )(AActor *,UPrimitiveComponent *,int32,bool,const FHitResult &)' to 'void (__cdecl AMyActor::* )(AActor *)'	MyProject4

(if you find other errors, this is a result of my hasty editing job to try and make my code shorter for this post). Does anyone know where I’m going wrong?

Thanks in advance!
Craig

Hi Nachtmahr,

Your answer guided me towards the problem. I was accidentally using OnActorBeginOverlap (which only likes AActor) for my AddDynamic lines, when I should have been using OnComponentBeginOverlap, which takes all the arguments.

Thank you for your help! :slight_smile:

Glad you figured it out Cheers =)

I alos has this problem ,which has troubled me for a long time!
Thanks a lot!