Unexpected behavior with SaveGame

Hello guys,

I have a class UFPSSaveGame derived from USaveGame which holds properties to save and another class - SaveGameManager. There are structures and arrays describing player profile, collected items in-game and few other things. These things are saving properly.

The problem appeared when I had to implement save versioning. The idea was not to migrate save, but simply use empty instance.

In UFPSSaveGame constructor I have something like “SaveVersion = 1;”. When game calls LoadGameFromSlot for old SaveGame (with SaveVersion 0 for example), SaveVersion value doesn’t load properly. It looks it is using value set in constructor. I have an UPROPERTY() on uint32 SaveVersion. When I moved “SaveVersion = 1;” from UFPSSaveGame’s contstructor to LoadMethod (simply “SaveGameInstance->SaveVersion = 1;”) it worked as expected.

The problem is when I increment SaveVersion in code in UFPSSaveGame constructor, it should print “SAVE NOT OK” (because saved file had another version) and use created default SaveGameObject, but it always print “SAVE OK!”.

void UFPSSaveGameManager::Load()
{
	SaveGameInstance = Cast<UFPSSaveGame>(UGameplayStatics::CreateSaveGameObject(UFPSSaveGame::StaticClass()));

	UFPSSaveGame * LoadedInstance = Cast<UFPSSaveGame>(UGameplayStatics::LoadGameFromSlot(SaveGameInstance->SaveSlotName, SaveGameInstance->UserIndex));

	if (LoadedInstance)
	{
		if (LoadedInstance->SaveVersion == SaveGameInstance->SaveVersion)
		{
			DEBUG_MESSAGE("SAVE OK!");
			SaveGameInstance = LoadedInstance;
		}
		else 
		{
			DEBUG_MESSAGE("SAVE NOT OK!");
		}
	}
}

So, how does it work?! Why LoadGameFromSlot doesn’t override default value set in constructor?

Well, it looks like that save system only saves deltas in relation to CDO. I wrote my own method to handle saving/loading game basing on UGameplayStatics implementation.