From bff484f139cd77ab3f934b231f3e6f79cf8a3a7d Mon Sep 17 00:00:00 2001 From: Louis Hobbs Date: Wed, 28 Jun 2023 22:58:58 +0100 Subject: [PATCH] Reload Current Level on Character Destruction --- Source/Nakatomi/PlayerCharacter.cpp | 9 ++++++++- Source/Nakatomi/PlayerCharacter.h | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Source/Nakatomi/PlayerCharacter.cpp b/Source/Nakatomi/PlayerCharacter.cpp index 7db8913..766a388 100644 --- a/Source/Nakatomi/PlayerCharacter.cpp +++ b/Source/Nakatomi/PlayerCharacter.cpp @@ -4,6 +4,7 @@ #include "PlayerCharacter.h" // You can remove these, this is just to get intellisense to work #include +#include #include "InputTriggers.h" #include "EnhancedInputComponent.h" @@ -77,6 +78,13 @@ void APlayerCharacter::BeginPlay() } } +void APlayerCharacter::Destroyed() +{ + Super::Destroyed(); + + UGameplayStatics::OpenLevel(GetWorld(), FName(GetWorld()->GetMapName())); +} + // Called every frame void APlayerCharacter::Tick(float DeltaTime) { @@ -318,7 +326,6 @@ void APlayerCharacter::OnDamaged() void APlayerCharacter::OnDeath() { Super::OnDeath(); - UE_LOG(LogTemp, Error, TEXT("YOU ARE DEAD!")); this->DetachFromControllerPendingDestroy(); this->GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision); diff --git a/Source/Nakatomi/PlayerCharacter.h b/Source/Nakatomi/PlayerCharacter.h index 665dea2..df0d773 100644 --- a/Source/Nakatomi/PlayerCharacter.h +++ b/Source/Nakatomi/PlayerCharacter.h @@ -91,6 +91,8 @@ protected: virtual void BeginPlay() override; public: + virtual void Destroyed() override; + // Called every frame virtual void Tick(float DeltaTime) override;