1...
2void AUnrealCPPCharacter::OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
3{
4 if (OtherActor && (OtherActor != this) && OtherComp)
5 {
6 GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Overlap Begin"));
7 }
8}
9
10void AUnrealCPPCharacter::OnOverlapEnd(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
11{
12 if (OtherActor && (OtherActor != this) && OtherComp)
13 {
14 GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Overlap End"));
15 }
16}
17
1public
2 ...
3
4 // declare overlap begin function
5 UFUNCTION()
6 void OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
7
8 // declare overlap end function
9 UFUNCTION()
10 void OnOverlapEnd(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
11
1void ALightSwitchCodeOnly::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
2{
3 // Other Actor is the actor that triggered the event. Check that is not ourself.
4 if ( (OtherActor != nullptr ) && (OtherActor != this) && ( OtherComp != nullptr ) )
5 {
6 // Turn off the light
7 PointLight->SetVisibility(false);
8 }
9}
1AUnrealCPPCharacter::AUnrealCPPCharacter()
2{
3 ...
4
5 // declare overlap events
6 TriggerCapsule->OnComponentBeginOverlap.AddDynamic(this, &AUnrealCPPCharacter::OnOverlapBegin);
7 TriggerCapsule->OnComponentEndOverlap.AddDynamic(this, &AUnrealCPPCharacter::OnOverlapEnd);
8
9}
10