OnComponentBeginOverlap.AddDynamic says no instance of the function template matches the argument list?

DualBall

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? 

JaMiT

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.

edited at
0

Comments

0 comments
Login to comment

Related

CUDA template error: no instance of function template matches the argument list

No instance of function template "ExtractSpherical_kernel" matches the argument list

no instance of function template matches the argument list (trying to print array)

C++ no instance of function template matches the argument list

No instance of function template "std::make_pair" matches the argument list

no instance of function template matches the argument list i dont know why

No instance of function template "max" matches the argument list argument types are (int, int)

No instance of function template matches the argument list, argument types are: (std::string, CommandLineArgumentTypes)

No instance of overloaded function matches the argument list

c++ template - More than one instance of overloaded function matches the argument list

How can I fix a "no instance of function template 'Defer' matches the argument list" error in C++?

C++ template class: No instance of constructor matches the argument list

Error No instance of overloaded function "getline" matches the argument list

no instance of overloaded function "std::make_unique" matches the argument list

no instance of constructor matches the argument list

no instance of "getline" matches the argument list

no instance of constructor "AcademicStaff::AcademicStaff" matches the argument list

Error passing Eigen matrix to a function in C++: "no instance of overloaded function matches the argument list"

More than one instance of overloaded function matches the argument list and I can't find where the error happens

C++ No instance of overloaded function matches the argument list when calling std::replace()

no instance of overloaded function "std::make_unique" matches the argument list, but works with unique_ptr constructor

No instance of overloaded function winrt::Windows::UI::Xaml::Controls::Primitives::SelectorItem::Content matches the argument list

C++ more than one instance of overloaded function matches the argument list when creating a header file

c++ struct in map as value - error "no instance of overloaded function matches the argument list"

C++ and SFML, no instance of the overloaded function "sf::RenderWindow.draw()" matches the argument list

c++ getline() error, no instance of overload function "getline" matches the argument list

How to fix "no instance of overloaded function "getline" matches the argument list" when using getline with an int

lambda function doesn't matches argument list

Using GetLine with ifstream - no instance of "getline" matches the argument list