Unreal engine simple collision detection C++

Hello. So, I am new to unreal engine, and I wanted to check if a Pawn is colliding with an Actor using UBoxComponent, then Print a message into the debug. But what I found was for UE 4 and not for UE 5 (Unreal engine 5.4.2):

Box = CreateDefaultSubobject(TEXT(“Box”));
Box.OnComponentHit.AddDynamic(this,&ADoor::Collide);

The function Collide:

void ADoor::Collide(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool fromSweep, const FHitResult& result){
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, FString::Printf(TEXT(“World delta for current frame equals %f”), GetWorld()->TimeSeconds));
}

The problem is there is no AddDynamic function for OnComponentHit for UBoxComponent in UE 5 (Unreal engine 5.4.2)

Box->OnComponentHit.AddDynamic(this, &ADoor::Collide);

and cpp definition for the hit inside of the door class:

void ADoor::Collide(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComponent, FVector NormalImpulse, const FHitResult& Hit) {

}

You can use the dot operator (.) only when accessing a direct reference of an object.
Here the box is a pointer. Pointers are accessed through the arrow operator (->)

(post deleted by author)

Thanks for the solution.

Please mark the correct implementation as a solution so that it’s seen in the forum as resolved :).

You shouldn’t bind functions to delegates in the constructor though, since those get serialized to the asset, and in turn to all the children of that class, which can be really problematic and there is no easy way to remove them really

You could reference a function inside of the same class and have that call an interface on the OtherActor or OtherComponent to not directly bind it.

As the name infers. Dynamic binding can be bound and unbound at runtime. The problem would rather stem from the inclusion of the class ADoor.