playgameservices / play-games-plugin-for-unity

Google Play Games plugin for Unity
Other
3.43k stars 953 forks source link

Save opens and data can be loaded or saved offline even with source set to "DataSource.ReadNetworkOnly" #3191

Open Gamengineer314 opened 1 year ago

Gamengineer314 commented 1 year ago

Hello, I am trying to implement the Play Games plugin in my game and, when I load or save some data with the Saved Games, I want to know if the game actually managed to get the data from the cloud or to save the data to the cloud and not from some local cache thing. I am trying to make it so that the users can see when their data was successfully saved or loaded and when it failed (for example if they were offline). But I can't figure out a way to see if the save update or the load actually worked or not (and I don't consider a local only load or save as a success...). Wether I am offline or not, the status is always 'Success' and some data always comes when loading. That's why I set the source parameter to DataSource.ReadNetworkOnly when I open the save (here is the line of code I use : PlayGamesPlatform.Instance.SavedGame.OpenWithAutomaticConflictResolution(fileName, DataSource.ReadNetworkOnly, ConflictResolutionStrategy.UseLongestPlaytime, callback);) and I thought I would get an error or an empty data or something like that when the game tries to load a save or update a save while being offline. But it doesn't change anything. I still get my data and the status is still 'Success'.

Not sure if it's an issue with the plugin or if it's intended or if I misunderstood something or if I'm doing something wrong but if anyone has a way to do what I need (know wether an action was done online or if it failed and was done locally only), I would love to see it :)

(Also, I'm using version 0.9.62 of the plugin)

smile616 commented 1 year ago

Hey @Gamengineer314

there is hasChangePending method on the SnapshotMetadata: https://developers.google.com/android/reference/com/google/android/gms/games/snapshot/SnapshotMetadata#hasChangePending()

You should be able to get access to in the plugin, too

Gamengineer314 commented 1 year ago

Hey @smile616, Thanks a lot for your answer ! I'm having a little problem in understanding what a SnapshotMetadata is and more importantly how to access it and how to access the hasChangePending() method from my script. I couldn't find any example or clear documentation on the Internet. I also tried to understand with the autocompletion in VS but no result so far...

Right now, my code for saving looks a little bit like this :

  public static void SaveToCloud()
  {
      //Open the save
      PlayGamesPlatform.Instance.SavedGame.OpenWithAutomaticConflictResolution(fileName, DataSource.ReadNetworkOnly, ConflictResolutionStrategy.UseLongestPlaytime, CommitUpdate);
  }

  public static void CommitUpdate(SavedGameRequestStatus status, ISavedGameMetadata metaData)
  {
      if (status == SavedGameRequestStatus.Success)
      {
          //Serialize my game's data (DataBase is the script that contains all the data needed to be saved)
          BinaryFormatter formatter = new BinaryFormatter();
          byte[] data;
          using (MemoryStream ms = new MemoryStream())
          {
              formatter.Serialize(ms, DataBase.newDB());
              data = ms.GetBuffer();
          }

          //Update the save
          SavedGameMetadataUpdate update = new SavedGameMetadataUpdate.Builder()
              .WithUpdatedDescription("Last save : " + DateTime.Now.ToString())
              .Build();
          PlayGamesPlatform.Instance.SavedGame.CommitUpdate(metaData, update, data, AfterSave);
      }
  }

  public static void AfterSave(SavedGameRequestStatus status, ISavedGameMetadata metadata)
  {
      if (status == SavedGameRequestStatus.Success)
      {
          if (???.hasChangePending()) //How can I access this method?
          {
              Debug.Log("Save failed because of some connexion issue");
          }
          else
          {
              Debug.Log("Save worked :)");
          }
      }
  }

And it's pretty much the same for loading.

Now I'm guessing I have to call the hasChangePending() method you told me about in my AfterSave() function (wich is the callback I give to the PlayGamesPlatform.Instance.SavedGame.CommitUpdate() method) but I don't understand how 🤔

rahulnaik906 commented 1 year ago

Did anyone find an answer to this ?

Timothy-Bellaiche commented 11 months ago

I'm still having this issue, and it is the cause of many save wipes in our player base. Looking at the source code, the DataSource.ReadNetworkOnly parameter isn't even used in the OpenWithAutomaticConflictResolution, method. So it's more a not implemented problem than something not working.

Do you have any plans to fix this? If not, you should remove this parameter as it is extremely misleading.