Exploring how the save game object is saved in Source code I found how to use Proxy Archive.
So I was able to expose 2 simple general-purpose save and load functions to blueprints.
h
UFUNCTION(BlueprintCallable)
static TArray<uint8> SaveToBinaryArray(UObject* Object);
UFUNCTION(BlueprintCallable)
static void LoadFromBinaryArray (TArray<uint8> SaveData, UObject* Object);
cpp
TArray<uint8> SomeSaveLoadClass::SaveToBinaryArray(UObject* Object)
{
TArray<uint8> SaveData;
FMemoryWriter MemoryWriter(SaveData, true);
FObjectAndNameAsStringProxyArchive Ar(MemoryWriter, false);
Object->Serialize(Ar); return SaveData;
}
void SomeSaveLoadClass::LoadFromBinaryArray(const TArray<uint8> SaveData, UObject* Object)
{
FMemoryReader MemoryReader(SaveData, true);
FObjectAndNameAsStringProxyArchive Ar(MemoryReader, false);
Object->Serialize(Ar);
}
This 2 simple functions can solve many different problems with automatic saving state of Any UObject.
Just call the function and all properties will be saved into binary array.
You than can do with it everythink you want. Test somethink and revert back. Clone Object. Save persistant state of object and write it in file.
This is similar to how JsonUtility.ToJson and FromJsonOverride works in Unity.
Saving thousands of objects is instant. Loading takes a little bit of time.
I find this functions very helpful and would like to have them In Engine for everyone.
Is it worth it trying to make a pull request with it? Or I should just create free plugin?