Other types such int string or class reference are serialized with current values and not default ones. So the problem only exists with blueprint structs.
Here is 2 simple functions to make binarry array of saveabale variables on object and to override variables of object from binary array data.
#pragma once
#include "MemoryWriter.h"
#include "MemoryReader.h"
#include "ObjectAndNameAsStringProxyArchive.h"
#include "Archive.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "ObjectToBinaryArrayPlaginBPLibrary.generated.h"
UCLASS()
class UObjectToBinaryArrayPlaginBPLibrary : public UBlueprintFunctionLibrary
{
GENERATED_UCLASS_BODY()
//Saves Object's Saveable Variables into binary array
UFUNCTION(BlueprintCallable, Category = "ObjectToBinaryArray")
static TArray<uint8> ObjectToBinaryArray( UObject* O)
{
TArray<uint8> ObjectData;
FMemoryWriter MemoryWriter(ObjectData, true);
FObjectAndNameAsStringProxyArchive Ar(MemoryWriter, false);
Ar.ArIsSaveGame = true; //Set achive is savegame
//Ar.ArNoDelta = true;
Ar.ArSerializingDefaults = 0;
O->Serialize(Ar);
return ObjectData;
};
// Loads data to objects and overrides it's SavableVariables
UFUNCTION(BlueprintCallable, Category = "ObjectToBinaryArray")
static void BinaryArrayToObjectOverride(UObject* O , TArray<uint8> ObjectData)
{
FMemoryReader MemoryReader(ObjectData, true);
FObjectAndNameAsStringProxyArchive Ar(MemoryReader, false);
Ar.ArIsSaveGame = true;
//Ar.ArNoDelta = true;
Ar.ArSerializingDefaults = 0;
O->Serialize(Ar);
};
};
But Struckts are not saved correctly.