In this first episode, we set the foundation of our Unreal Engine 5.6 C++ Interaction System.
We’ll create a reusable interaction interface, build an InteractablesBase class, and add a sphere collision component to detect when the player enters and exits interaction range. Finally, we set up a simple UI widget to display prompts when interactable objects are nearby.
To prevent non-player actors from triggering OnInteractionRangeEntered() and OnInteractionRangeExited(), we explicitly check that the overlapping actor is the player by casting to him inside an if statement.
void AInteractablesBase::OnBeginOverlap(AActor* OverlappedActor, AActor* OtherActor)
{
if (AInteractionTutorialCharacter* PlayerCharacter = Cast<AInteractionTutorialCharacter>(OtherActor))
{
OnInteractionRangeEntered();
}
}
void AInteractablesBase::OnEndOverlap(AActor* OverlappedActor, AActor* OtherActor)
{
if (AInteractionTutorialCharacter* PlayerCharacter = Cast<AInteractionTutorialCharacter>(OtherActor))
{
OnInteractionRangeExited();
}
}
Download
0 formats
No download links available.
Unreal Engine 5.6 C++ Interaction System - Part 1: Interface, Base Class & UI Setup | NatokHD