I’m using FullSerializer to serialize a string and then upload it to a cloud.
So far, this is what I’ve got for the class that needs serializing:
[System.Serializable]
public class SavedGame
{
public string dataToSave ="";
}
[System.Serializable]
public class XboxOneDataClass
{
public SavedGame savedGames = new SavedGame();
}
dataToSave is the string containing EVERYTHING that needs saving in my game.
In my save code, I’m using this:
Debug.LogError("Attempting to save cloud data...");
Type myType = Type.GetType("XboxOneDataClass");
string serializedData = MyFullSerializer.Serialize(myType, xboxOneData);
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(serializedData);
GameSaveContainer container = gameSaveProvider.CreateContainer(c_saveContainerName);
// To store a value in the container, it needs to be written into a buffer, then stored with
// a blob name in a Dictionary.
DataWriter writer = new DataWriter();
writer.WriteBytes(bytes);
IBuffer dataBuffer = writer.DetachBuffer();
var updates = new Dictionary<string, IBuffer>();
updates.Add(c_saveBlobName, dataBuffer);
Debug.LogError("Data saved to buffer...");
GameSaveOperationResult result = await container.SubmitUpdatesAsync(updates, null, c_saveContainerDisplayName);
Debug.LogError("Submitting save game to cloud...");
if (result.Status == GameSaveErrorStatus.Ok)
{
Debug.LogError("SUCCESSFULLY Saved data : " + bytes);
}
else
{
Debug.LogError("SaveData FAILED: " + result.Status);
}
}
catch (Exception ex)
{
Debug.LogError("SaveData failed: " + ex.Message);
}
The error shown is “SaveData failed: Value cannot be null. Parameter name: key” in regards to the dataToSave string.
The dataToSave string is created in another script.
My question is, how do I ensure that that string isn’t null and is successfully passed to be submitted for uploading?
I’m not a genius at coding so please go easy on me!
Any help would be VERY much appreciated, thank you kindly