How do you serialize and deserialize a UObject to/from an FArchive file?

What is FArchive for? Is there a benefit using it over the USaveGame?
UGameplayStatics library has some methods to write UObjects to a USaveGame easily.

UCLASS()
class UYourOwnSaveGame : public USaveGame
{
	GENERATED_BODY()

public:

	UPROPERTY()
		FString SomeInformation = "";

};
UYourOwnSaveGame* YourOwnSaveGame = Cast<UYourOwnSaveGame>(UGameplayStatics::CreateSaveGameObject(UYourOwnSaveGame::StaticClass()));

if (IsValid(YourOwnSaveGame )) {
  YourOwnSaveGame->SomeInformation = "Testing";

  if (UGameplayStatics::SaveGameToSlot(YourOwnSaveGame , TEXT("SomeSaveName"), 0)) {
	// success
  }
}
1 Like