We’re using Unreal’s SaveGame features similarly to this tutorial.
Relevant actor variables are labeled as SaveGame and are accounted for when the actor gets serialized to a data container before getting written to a save file:
void UPKSaveActor::WriteFromActor(AActor* Actor, TArray<uint8>& Buffer)
{
FMemoryWriter MemWriter(Buffer);
FObjectAndNameAsStringProxyArchive Ar(MemWriter, true);
Ar.ArIsSaveGame = true;
Actor->Serialize(Ar);
}
That data container then gets desterilized when the file is loaded:
void UPKSaveActor::ReadToActor(AActor* Actor, TArray<uint8>& Buffer)
{
FMemoryReader MemReader(Buffer);
FObjectAndNameAsStringProxyArchive Ar(MemReader, true);
Ar.ArIsSaveGame = true;
Actor->Serialize(Ar);
}
This can become tricky if the actor asset is changed when a new version of the project comes out. The player’s old save files may not deserialize correctly when the game updates. Are there any good ways to deal with this while still using the built in Unreal serializers? Or any other strategies? We hope that we won’t have to create custom serializers and manually code in data conversions every time an actor is updated.