Question by
Lucius_1 · Sep 08, 2017 at 05:25 AM ·
google playgoogle play gamessave game
Problem reading saved game
I'm trying to implement progress saving through Google Services. It seems that the "Save" function occurs perfectly, the problem is when you tried to recover what was stored.
First, LoadData function:
public void LoadData()
{
//basically if we're connected to the internet, do everything on the cloud
if (Social.localUser.authenticated)
{
isSaving = false;
((PlayGamesPlatform)Social.Active).SavedGame.OpenWithManualConflictResolution("TESTE",
DataSource.ReadCacheOrNetwork, true, ResolveConflict, OnSavedGameOpened);
}
//this will basically only run in Unity Editor, as on device,
//localUser will be authenticated even if he's not connected to the internet (if the player is using GPG)
else
{
}
}
Then:
private void OnSavedGameOpened(SavedGameRequestStatus status, ISavedGameMetadata game)
{
//if we are connected to the internet
if (status == SavedGameRequestStatus.Success)
{
//if we're LOADING game data
if (!isSaving)
LoadGame(game);
//if we're SAVING game data
else
SaveGame(game);
}
else
{
}
}
private void LoadGame(ISavedGameMetadata game)
{
((PlayGamesPlatform)Social.Active).SavedGame.ReadBinaryData(game, OnSavedGameDataRead);
}
private void OnSavedGameDataRead(SavedGameRequestStatus status, byte[] savedData)
{
//if reading of the data was successful
if (status == SavedGameRequestStatus.Success) {
string cloudDataString;
//if we've never played the game before, savedData will have length of 0
if (savedData.Length == 0) {
//in such case, we want to assign "0" to our string
cloudDataString = "0";
//otherwise take the byte[] of data and encode it to string
} else {
cloudDataString = Encoding.ASCII.GetString (savedData);
}
texto.text = "" + cloudDataString;
pontos = int.Parse (cloudDataString);
} else {
}
}
The status of "OnSavedGameDataRead" comes as false :(
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612134419im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Google Sign in not working after publish 0 Answers
Does Google Play Games Service achievements support multiple profiles in a game? 0 Answers
leader board could not working and its can'tpost the score ? 1 Answer
Google Play Game services Resolution Exception with newer Google Repository version 2 Answers
Unity Codeless IAP, Google Play Services Sign-in, Leaderboards and Achievements NOT WORKING! 0 Answers