From c0d57dac8e024590d70004ec2635307a45a8081c Mon Sep 17 00:00:00 2001 From: baz Date: Wed, 10 Apr 2024 01:28:51 +0100 Subject: [PATCH] Check for Player in OnOverlapBegin on ALevelKeyPickup --- Source/Nakatomi/LevelKeyPickup.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Source/Nakatomi/LevelKeyPickup.cpp b/Source/Nakatomi/LevelKeyPickup.cpp index 447d980..af58d09 100644 --- a/Source/Nakatomi/LevelKeyPickup.cpp +++ b/Source/Nakatomi/LevelKeyPickup.cpp @@ -3,6 +3,7 @@ #include "LevelKeyPickup.h" #include "NakatomiGameInstance.h" +#include "PlayerCharacter.h" #include "Kismet/GameplayStatics.h" void ALevelKeyPickup::BeginPlay() @@ -18,15 +19,18 @@ void ALevelKeyPickup::BeginPlay() void ALevelKeyPickup::Tick(float DeltaTime) { Super::Tick(DeltaTime); -} +} void ALevelKeyPickup::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) { - if (auto gameInstance = Cast(UGameplayStatics::GetGameInstance(GetWorld()))) + if (Cast(OtherActor)) { - gameInstance->GetCurrentLevelManager()->IncrementCollectedLevelKeys(); + if (auto gameInstance = Cast(UGameplayStatics::GetGameInstance(GetWorld()))) + { + gameInstance->GetCurrentLevelManager()->IncrementCollectedLevelKeys(); + } + + Super::OnOverlapBegin(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult); } - - Super::OnOverlapBegin(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult); }