Reload Current Level on Character Destruction

This commit is contained in:
Louis Hobbs 2023-06-28 22:58:58 +01:00
parent 925be65769
commit bff484f139
2 changed files with 10 additions and 1 deletions

View File

@ -4,6 +4,7 @@
#include "PlayerCharacter.h" #include "PlayerCharacter.h"
// You can remove these, this is just to get intellisense to work // You can remove these, this is just to get intellisense to work
#include <Components/CapsuleComponent.h> #include <Components/CapsuleComponent.h>
#include <Kismet/GameplayStatics.h>
#include "InputTriggers.h" #include "InputTriggers.h"
#include "EnhancedInputComponent.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 // Called every frame
void APlayerCharacter::Tick(float DeltaTime) void APlayerCharacter::Tick(float DeltaTime)
{ {
@ -318,7 +326,6 @@ void APlayerCharacter::OnDamaged()
void APlayerCharacter::OnDeath() void APlayerCharacter::OnDeath()
{ {
Super::OnDeath(); Super::OnDeath();
UE_LOG(LogTemp, Error, TEXT("YOU ARE DEAD!"));
this->DetachFromControllerPendingDestroy(); this->DetachFromControllerPendingDestroy();
this->GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision); this->GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);

View File

@ -91,6 +91,8 @@ protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
public: public:
virtual void Destroyed() override;
// Called every frame // Called every frame
virtual void Tick(float DeltaTime) override; virtual void Tick(float DeltaTime) override;