How can I trigger a custom event when the player picks up an item using C++?

Hi everyone! I’m pretty new to Unreal Engine and just started learning gameplay programming with C++. Right now, I’m trying to build a very basic item pickup system. I’ve created an AItem class, and I want to trigger a custom event (like playing a sound or increasing the player’s score) when the player overlaps with the item and presses a key (e.g., ‘E’).

I’ve managed to set up the overlap detection using OnActorBeginOverlap, and I also bound input in the ACharacter class, but I’m not sure how to correctly reference the item and trigger a function inside it. Do I need to use an interface or cast the overlapping actor? Or is there a more elegant way to handle this in Unreal C++?

Any advice, examples, or even a quick breakdown of best practices when structuring this kind of interaction would really help me. Thanks in advance!

Or Overlap or press a Key… the two things at the same time is not possible.

A Event in C++ is a simple fuction and that is all.

Or this:

void OnActorBeginOverlap(AActor* OverlappedActor, AActor* Other)
{
     MyFunction();
}

Or this:

void OnSomeKeyPressed()
{
     MyFunction();
}

You can expose it as event in blueprint:

UFUNCTION(BlueprintNativeEvent)
void  MyFunction();

Or can expose it as fuction in blueprint:

UFUNCTION(BlueprintCallable)
void  MyFunction();

That’s all elegant it can be