Some Actor
and Component
classes provided with Unreal include event handlers in the form of virtual functions. This recipe will show you how to customize those handlers by overriding the virtual function in question.
Create an empty
Actor
in the Editor. Call itMyTriggerVolume
.Add the following code to the class header:
UPROPERTY() UBoxComponent* TriggerZone; UFUNCTION() virtual void NotifyActorBeginOverlap(AActor* OtherActor) override; UFUNCTION() virtual void NotifyActorEndOverlap(AActor* OtherActor) override;
Add the implementation for the preceding functions to the cpp file:
void AMyTriggerVolume::NotifyActorBeginOverlap(AActor* OtherActor) { GEngine->AddOnScreenDebugMessage(-1, 1, FColor::Red, FString::Printf(TEXT("%s entered me"),*(OtherActor->GetName()))); } void AMyTriggerVolume::NotifyActorEndOverlap(AActor* OtherActor) { GEngine->AddOnScreenDebugMessage(-1, 1, FColor::Red, FString::Printf(TEXT("%s left...