How to do OnBeginOverlap in C++?

Hi, I want to call the delegate OnBeginOverlap when the box collision is overlapped by the character. How to to do this?

What I am trying is:
MyTestClass.h

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnBeginOverlap);

	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Interaction")
		FOnBeginOverlap OnBeginOverlaped;

MyTestClass.cpp constructor
Box->OnComponentBeginOverlap.AddDynamic(this, &AMyTestClass::OnBeginOverlaped);

What I am doing wrong? I am getting the compiler error Incomplete type is not allowed
image_2022-06-14_160228111

You don’t need to declare a delegate, the delegate already exists in PrimitiveComponent.h.

You can find it there and see what parameters must be used. In this case you have to declare a function in .h:

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

And then indicate this function in AddDynamic:
Box->OnComponentBeginOverlap.AddDynamic(this, &AMyTestClass::OnOverlapBegin);

6 Likes

Thank You Sir very much , You just solved my issue :slight_smile: