From 804a752aa50e7c7eebc31148aee96111d6923147 Mon Sep 17 00:00:00 2001 From: baz Date: Tue, 28 May 2024 01:55:46 +0100 Subject: [PATCH] Move save logic from NakatomiCharacter to PlayerCharacter --- Source/Nakatomi/NakatomiCharacter.cpp | 10 ---------- Source/Nakatomi/PlayerCharacter.cpp | 10 ++++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Source/Nakatomi/NakatomiCharacter.cpp b/Source/Nakatomi/NakatomiCharacter.cpp index e4d9834..221452e 100644 --- a/Source/Nakatomi/NakatomiCharacter.cpp +++ b/Source/Nakatomi/NakatomiCharacter.cpp @@ -5,7 +5,6 @@ #include "NakatomiCMC.h" #include "NakatomiGameInstance.h" -#include "Kismet/GameplayStatics.h" // Sets default values ANakatomiCharacter::ANakatomiCharacter(const FObjectInitializer& ObjectInitializer) : Super( @@ -32,15 +31,6 @@ 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 diff --git a/Source/Nakatomi/PlayerCharacter.cpp b/Source/Nakatomi/PlayerCharacter.cpp index c737931..9716cc9 100644 --- a/Source/Nakatomi/PlayerCharacter.cpp +++ b/Source/Nakatomi/PlayerCharacter.cpp @@ -13,6 +13,7 @@ #include "InputTriggers.h" #include "InteractableComponent.h" #include "NakatomiCMC.h" +#include "NakatomiGameInstance.h" #include "WeaponThrowable.h" #include "NiagaraFunctionLibrary.h" #include "GameFramework/CharacterMovementComponent.h" @@ -80,6 +81,15 @@ void APlayerCharacter::BeginPlay() AimSensitivity = DefaultAimSensitivity; + if (UNakatomiGameInstance* gameInstance = Cast(UGameplayStatics::GetGameInstance(GetWorld()))) + { + if (UNakatomiSaveGame* Save = gameInstance->GetSaveGameObject()) + { + //TODO: More loading here + GetHealthComponent()->SetCurrentHealth(Save->PlayerHealth); + } + } + if (!this->ActorHasTag(FName("Player"))) { this->Tags.Add(FName("Player"));