Move save logic from NakatomiCharacter to PlayerCharacter

This commit is contained in:
baz 2024-05-28 01:55:46 +01:00
parent 0e9a36f1c9
commit 804a752aa5
2 changed files with 10 additions and 10 deletions

View File

@ -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<UNakatomiCMC>(GetCharacterMovement());
if (UNakatomiGameInstance* gameInstance = Cast<UNakatomiGameInstance>(UGameplayStatics::GetGameInstance(GetWorld())))
{
if (UNakatomiSaveGame* Save = gameInstance->GetSaveGameObject())
{
//TODO: More loading here
GetHealthComponent()->SetCurrentHealth(Save->PlayerHealth);
}
}
}
// Called every frame

View File

@ -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<UNakatomiGameInstance>(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"));