# Save game always has default values

**URL:** <https://forums.unrealengine.com/t/save-game-always-has-default-values/476543>\
**Category:** Editor Scripting\
**Tags:** savegame, default-value, unreal-engine, saving, CPP, question\
**Created:** [December 30, 2020, 10:20pm UTC](https://forums.unrealengine.com/t/save-game-always-has-default-values/476543 "2020-12-30T22:20:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![AgentArachnid66](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AgentArachnid66](https://forums.unrealengine.com/u/AgentArachnid66)\
**Post date:** [December 30, 2020, 10:20pm UTC](https://forums.unrealengine.com/t/save-game-always-has-default-values/476543/1 "2020-12-30T22:20:03Z")

</div>

I’m trying to make a simple saving and loading system and have been following the Docs for help. I have the following code:

```
// Declaration in the .h file
 UCustomSave* saveGame;

```

.cpp file

```
// Loads the topology from a struct that can be saved to a save game object.
void UNeuralNetwork::Load(FString customSlotName) {
	FString test;
	if (UGameplayStatics::DoesSaveGameExist(customSlotName, 0)) {
		UE_LOG(LogTemp, Warning, TEXT("Save game exists in slot: %s"), *customSlotName);

		// Retrieve and cast the USaveGame object to UCustomSave.
		this->saveGame= Cast<UCustomSave>(UGameplayStatics::LoadGameFromSlot(customSlotName, 0));

		test = this->saveGame->prevSaved ? "true" : "false";

		// The operation was successful, so LoadedGame now contains the data we saved earlier.
		UE_LOG(LogTemp, Warning, TEXT("Has been Previously Saved? %s"), *test);

	}
}

void UNeuralNetwork::Save(FString customSlotName) {
	FString test;
	if (this->saveGame== nullptr) {
		this->saveGame= Cast<UCustomSave>(UGameplayStatics::CreateSaveGameObject(UCustomSave::StaticClass()));
	}
	// Set data on the savegame object.
	this->saveGame->prevSaved = true;

	// Save the data immediately.
	if (UGameplayStatics::SaveGameToSlot(this->saveGame, customSlotName, 0))
	{
		UE_LOG(LogTemp, Warning, TEXT("Save was Successful in slot: %s"), *customSlotName);
	}

}

```

I’m using prevSaved as a boolean that will be set on the .h file of the save game object UCustomSave as false. This is purely for testing, but it is always the default value.

I get the following results after calling Save and then Load:

```
LogTemp: Warning: Save was Successful in slot: Test
LogTemp: Warning: Save game exists in slot: Test
LogTemp: Warning: Has been Previously Saved? true

```

I’m not sure where I am going wrong so any help would be much appreciated
