Why Isn't my event handler being called on a actor spawned at runtime from C++?

So I have a actor that is spawned at runtime with a collision component. My problem that the OnComponentBeginOverlap function that I set in C++ in BeginPlay is never called while whenever i add a blueprint event handler then that BP function is called.

The function signatures match and it has a UFUNCTION() macro.

What exactly is my problem?

Sorry could use some more details. Can you show some source?

Are you attaching the component in BeginPlay, OnConstruction or in the C++ constructor? Is the component instance persistent from BeginPlay or does it spawn during game-play?

Sorry for the late reply. I bind the function in BeginPlay

    CollisionComponent->OnComponentBeginOverlap.AddDynamic(this, &ABaseHitBox::OnAttackOverlap);

The prototype is

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

The component is spawned at runetime called from an anim notify.

Do you bind the collision after you spawn the component?

Well I call the bind function in BeginPlay so i guess so.

If your spawning the component from an anim notify during runtime you need to bind the begin overlap then. BeginPlay on the parent actor is only called when the parent actor begins play and the begin overlap binding needs to happen on the particular instance of the component that you intent to check is overlapping.

I see, OK I’ll give it a try and see what happens.

Edit:OK I got it to work by binding it from the pointer returned by the spawn actor function. Thanks.