From 0e9a36f1c900dea9a6009eb21dd0bc4aae220767 Mon Sep 17 00:00:00 2001 From: baz Date: Mon, 27 May 2024 20:33:38 +0100 Subject: [PATCH] Load Health from save --- Source/Nakatomi/NakatomiCharacter.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Source/Nakatomi/NakatomiCharacter.cpp b/Source/Nakatomi/NakatomiCharacter.cpp index df9c92e..e4d9834 100644 --- a/Source/Nakatomi/NakatomiCharacter.cpp +++ b/Source/Nakatomi/NakatomiCharacter.cpp @@ -4,6 +4,8 @@ #include "NakatomiCharacter.h" #include "NakatomiCMC.h" +#include "NakatomiGameInstance.h" +#include "Kismet/GameplayStatics.h" // Sets default values ANakatomiCharacter::ANakatomiCharacter(const FObjectInitializer& ObjectInitializer) : Super( @@ -30,6 +32,15 @@ void ANakatomiCharacter::BeginPlay() SetInventoryToDefault(); NakatomiCMC = Cast(GetCharacterMovement()); + + if (UNakatomiGameInstance* gameInstance = Cast(UGameplayStatics::GetGameInstance(GetWorld()))) + { + if (UNakatomiSaveGame* Save = gameInstance->GetSaveGameObject()) + { + //TODO: More loading here + GetHealthComponent()->SetCurrentHealth(Save->PlayerHealth); + } + } } // Called every frame