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"
// You can remove these, this is just to get intellisense to work
#include <Components/CapsuleComponent.h>
#include <Kismet/GameplayStatics.h>
#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);

View File

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