- Home /
Google Cloud Saving Byte array Obsolete error
Hello, i am currently having an issue with the google cloud saving system. I believe i have all the serialization and deserialization scripts correct, but when i try to save or load anything, i get the following error saying that Byte paramaters are obsolote, and i should use SByte instead. I believe the issue is originating from the CommitUpdate() and ReadBinaryData() functions, but they only accept Byte as paramaters. I've searched everywhere for a solution but came up empty. Does anyone have similar issues? Is cloud saving just not compatible with unity yet?
CLOUD SAVE SCRIPT
//overwrites old file or saves a new one
public void SaveToCloud()
{
if (Authenticated)
{
Debug.Log("Saving progress to the cloud... filename: " + m_saveName);
m_saving = true;
//save to named file
((PlayGamesPlatform)Social.Active).SavedGame.OpenWithAutomaticConflictResolution(
m_saveName, //name of file. If save doesn't exist it will be created with this name
DataSource.ReadCacheOrNetwork,
ConflictResolutionStrategy.UseLongestPlaytime,
SavedGameOpened);
}
else
{
Debug.Log("Not authenticated!");
}
}
//save is opened, either save or load it.
private void SavedGameOpened(SavedGameRequestStatus status, ISavedGameMetadata game)
{
//check success
if (status == SavedGameRequestStatus.Success)
{
//saving
if (m_saving)
{
//read bytes from save
byte[] data = ToBytes();
//create builder. here you can add play time, time created etc for UI.
SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder();
builder = builder
//.WithUpdatedPlayedTime(totalPlaytime)
.WithUpdatedDescription("Saved game at " + DateTime.Now);
//if (savedImage != null)
//{
// // This assumes that savedImage is an instance of Texture2D
// // and that you have already called a function equivalent to
// // getScreenshot() to set savedImage
// // NOTE: see sample definition of getScreenshot() method below
// byte[] pngData = savedImage.EncodeToPNG();
// builder = builder.WithUpdatedPngCoverImage(pngData);
//}
builder = builder.WithUpdatedPngCoverImage(getScreenshot().EncodeToPNG());
SavedGameMetadataUpdate updatedMetadata = builder.Build();
//saving to cloud
Debug.Log(((PlayGamesPlatform)Social.Active).GetUserDisplayName() + " Saved " + data.Length + " bytes");
((PlayGamesPlatform)Social.Active).SavedGame.CommitUpdate(game, updatedMetadata, data, SavedGameWritten);
//loading
}
else
{
((PlayGamesPlatform)Social.Active).SavedGame.ReadBinaryData(game, SavedGameLoaded);
}
//error
}
else
{
Debug.LogWarning("Error opening game: " + status);
}
}
SERIALIZATION/DESERIALIZATION
//merge local save with cloud save. Here is where you change the merging betweeen cloud and local save for your setup.
private void MergeWith(PlayerInfo other)
{
if (other != null)
{
playerInfo = other;
}
else
{
playerInfo = new PlayerInfo();
Debug.Log("Loaded save string doesn't have any content");
}
}
//return saveString as bytes
//https://stackoverflow.com/questions/1446547/how-to-convert-an-object-to-a-byte-array-in-c-sharp
private byte[] ToBytes()
{
BinaryFormatter bf = new BinaryFormatter();
using (var ms = new MemoryStream())
{
bf.Serialize(ms, playerInfo);
Debug.Log("Saving " + ms.ToArray().Length + " bytes");
return ms.ToArray();
//return Array.ConvertAll(ms.ToArray(), b => unchecked((sbyte)b));
}
}
//take bytes as arg and return string
private PlayerInfo FromBytes(byte[] bytes)
{
Debug.Log("Loading " + bytes.Length + " bytes");
using (var memStream = new MemoryStream(bytes))
{
var binForm = new BinaryFormatter();
var obj = binForm.Deserialize(memStream) as PlayerInfo;
return obj;
}
}
@UniqueXDream94 , did you ever find an answer to this issue? I am encountering the same problem right now.
Same issue -- the radio silence on this is concerning. I suspect the library is no longer properly maintained.
Your answer
Follow this Question
Related Questions
Google play cloud upload and download game data Unity android game 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Filestream/SaveManager 2 Answers