Binding Overlap delegate in UBoxComponent subclass

I’m new to c++ and can’t quite get a handle on delegate binding. I’m trying to write a class derived from UBoxComponent that binds to the OnComponentBeginOverlap dynamic multicast delegate.

I also have a dynamic array of primitive components declared for this class. What I would like this component to do is maintain an index of any and all components from other actors it is overlapping with. Here’s what I’ve got so far:

my h:

#pragma once

#include "Components/BoxComponent.h"
#include "FloorSensor.generated.h"

UCLASS()
class MYPROJECT_API UFloorSensor : public UBoxComponent
{
    GENERATED_BODY()

public:

    UFloorSensor(const FObjectInitializer& ObjectInitializer);
    
    FComponentBeginOverlapSignature StartOverlappingDelegate;
    
    UFUNCTION()
    void StartOverlappingDelegate(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
    
    bool bIsOverlapping;
    
    // Stores overlapping components whose parent actor implements certain interface
    TArray<UPrimitiveComponent*> OverlappingComponents;
};

my ccp:

#include "MyProject.h"
#include "FloorSensor.h"

UFloorSensor::UFloorSensor(const FObjectInitializer& ObjectInitializer)
    : Super(ObjectInitializer)
{
	
}

void UFloorSensor::StartOverlappingDelegate(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{

}

I’m getting several errors:

error C2365: 'UFloorSensor::StartOverlappingDelegate' : redefinition; previous definition was 'data member'

error C2064: term does not evaluate to a function taking 5 arguments

I’d be hugely grateful for any help here.

Hello, jasputin

The error occurs because you have the same name StartOverlappingDelegate for the variable and for the function.

Hoep this helped!

Cheers!

Thanks for the reply. That makes sense. I guess I’m not sure what to do with the FComponentBeginOverlapSignature delegate type name in a derived class. Could you clue me in? I’m trying to follow the docs here (https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Delegates/index.html) but can’t quite make sense of it.

Got it working pretty much by just leaving out the delegate type declaration (and getting the right delegate function signature. So now I really don’t know where/how to use FComponentBeginOverlapSignature, but I’ll open a separate question for that when the time comes.

Here’s relevant code:

h:

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

ccp:

// In constructor
OnComponentBeginOverlap.AddDynamic(this, &UFloorSensor::StartOverlappingDelegate);

// member function defintion
void UFloorSensor::StartOverlappingDelegate(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
    UE_LOG(LogTemp, Log, TEXT("Component started overlapping"));
}

This is pretty intuitive and I would have done this first off if I hadn’t read through all the delegates documentation.