In a cpp file, my use of:
BoxComp->OnComponentBeginOverlap.AddDynamic(this, &AAICharacter::OnBoxOverlap);
BoxComp->OnComponentEndOverlap.AddDynamic(this, &AAICharacter::OnBoxEndOverlap);
got the following error:
cannot convert argument 2 from 'void (_cdecl AAICharacter::*)(AActor*,UPrimitiveComponent*,int32,bool,const FHitResult &)' to 'void (_cdecl AAICharacter::*)(UPrimitiveComponent*, AActor*,UPrimitiveComponent*,int32,bool,const FHitResult &)
Here's what my header file with the associated function looks like. Some of the code has been omitted to try and create what I thought was a minimal reproducible example; if I omitted anything valuable based on my lack of expertise just lmk:
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Engine/DataTable.h"
#include "Subtitle.h"
#include "Components/BoxComponent.h"
#include "Components/AudioComponent.h"
#include "AICharacter.generated.h"
/**
* The purpose of this class is to create a dummy AI for testing out the code for character interactions.
*/
UCLASS()
class GV_PROJECT_API AAICharacter : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AAICharacter();
private:
UFUNCTION()
void OnBoxOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherIndex, bool bFromSweep, const FHitResult & SweepResult);
UFUNCTION()
void OnBoxEndOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherIndex)
protected:
/*If the player is inside this box component he will be able to initiate a conversation with the pawn*/
UPROPERTY(VisibleAnywhere)
UBoxComponent* BoxComp;
Is anyone familiar with this error?
The error is fairly self-explanatory.
cannot convert argument 2 from 'void (_cdecl AAICharacter::*)(AActor*,UPrimitiveComponent*,int32,bool,const FHitResult &)' to 'void (_cdecl AAICharacter::*)(UPrimitiveComponent*, AActor*,UPrimitiveComponent*,int32,bool,const FHitResult &)
The second argument in the indicated lines (so &AAICharacter::OnBoxOverlap
and &AAICharacter::OnBoxEndOverlap
) have the first type listed in the message, while the function being called (AddDynamic()
) expects the second type. Sometimes differing types is not a problem, but in this case there is no way to convert from one to the other.
The only trick I see comes after comparing the types in question. It helps to insert spaces so that things line up better.
void (_cdecl AAICharacter::*)( AActor*,UPrimitiveComponent*,int32,bool,const FHitResult &)
void (_cdecl AAICharacter::*)(UPrimitiveComponent*, AActor*,UPrimitiveComponent*,int32,bool,const FHitResult &)
The two member functions take fewer parameters than expected. If this is the only place those functions are used, the additional UPrimitiveComponent*
parameter could be added directly to them. Otherwise, you might want to introduce wrapper functions that have the needed signature, ignore their first parameter, and call the method (one wrapper would call OnBoxOverlap()
, while the other would call OnBoxEndOverlap()
). For example:
UFUNCTION()
void OnBoxOverlapWrapper(UPrimitiveComponent* /*ignored*/, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherIndex, bool bFromSweep, const FHitResult & SweepResult)
{
OnBoxOverlap(OtherActor, OtherComp, OtherIndex, bFromSweep, SweepResult);
}
This comes with a caveat: do you know the significance of the parameter you are ignoring? Your code might contain a currently-unnoticed bug originating from not making use of that first parameter.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments