Compiler error on OnComponentBeginOverlap.Add

I have a UCLASS() called ACheckpoint with the following UBoxComponent member:

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Gameplay")
    UBoxComponent* Trigger;

It is initialized in my class’s constructor like so:

    Trigger = ObjectInitializer.CreateDefaultSubobject<UBoxComponent>(this, TEXT("Trigger"));
    Trigger->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
    Trigger->SetBoxExtent(FVector::FVector(32.0f, 480.0f, 480.0f), true);
    Trigger->OnComponentBeginOverlap.Add(&ACheckpoint::OnTriggerCheckpoint); // ERROR: Reference to type 'const TScriptDelegate<FWeakObjectPtr> could not bind to an rvalue of type 'void (Checkpoint::*)(class Actor *, class UPrimitiveComponent*, int32, bool, const FHitResult&
    Trigger->bGenerateOverlapEvents = true; // Enabled by default
    Trigger->AttachTo(RootComponent);

The same class also features a function called OnTriggerCheckpoint with the following signature:

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

The OnTriggerCheckpoint method is implemented in the class’s .cpp file.

When attempting to compile my code, I get the following error on Trigger->OnComponentBeginOverlap.Add(&ACheckpoint::OnTriggerCheckpoint);

Reference to type 'const TScriptDelegate<FWeakObjectPtr> could not bind to an rvalue of type 'void (Checkpoint::*)(class Actor *, class UPrimitiveComponent*, int32, bool, const FHitResult&

What am I doing wrong here?

Try binding using .AddDynamic() instead.

Basically, your code will look like this :

Trigger->OnComponentBeginOverlap.AddDynamic(this,&ACheckpoint::OnTriggerCheckpoint);

OnComponentBeginOverlap is a dynamic delegate, I don’t that Add() will do good with that, but I use AddDynamic plenty in my code and it works fine.

Hope this helps!

Mick