x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

OnOverlap AddDynamic error C2664

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

Product Version: UE 4.11
Tags:
more ▼

asked Jun 05 '16 at 11:25 PM in C++ Programming

avatar image

pitman1991
1 1 2 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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 =)

more ▼

answered Jun 05 '16 at 11:45 PM

avatar image

Nachtmahr
7k 143 28 172

avatar image pitman1991 Jun 07 '16 at 05:10 PM

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! :)

avatar image Nachtmahr Jun 07 '16 at 05:12 PM

Glad you figured it out Cheers =)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

more ▼

answered Oct 17 '16 at 12:54 PM

avatar image

a409197988
6 2 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question