Loading a Variable
To load a variable, you must first load the SaveGame
object using UGameplayStatics::LoadGameFromSlot
. This creates a new instance of the SaveGame
object.
Again, in this case, an empty SaveGame
object is first created, so the default SaveSlotName
and UserIndex
can be read from it. This is an optional step and may not apply in all game implementations.
Once the new SaveGame
object has been loaded from the hard drive, the variable values can be read from it and assigned to the necessary Actors or classes, or used directly as shown here.
UMySaveGame* LoadGameInstance = Cast<UMySaveGame>(UGameplayStatics::CreateSaveGameObject(UMySaveGame::StaticClass()));
LoadGameInstance = Cast<UMySaveGame>(UGameplayStatics::LoadGameFromSlot(LoadGameInstance->SaveSlotName, LoadGameInstance->UserIndex));
FString PlayerNameToDisplay = LoadGameInstance->PlayerName;
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, PlayerNameToDisplay);
}
출처 : https://docs.unrealengine.com/en-us/Gameplay/SaveGame/Code
언리얼 홈페이지.