Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

[Google Play Games] Cloud Save is not saving

Discussion in 'Android' started by alexandros356, Oct 31, 2019.

  1. alexandros356

    alexandros356

    Joined:
    Dec 3, 2012
    Posts:
    105
    Hi guys, Have you experienced any issue related to the play games cloud save?
    It is not working well for us. The game data is not being saved with no error in the log. And when the user loads the data it get the previous data.

    Thanks!
     
  2. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    9,799
  3. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Show the code and provide steps to reproduce, and the results of your debugging.
     
  4. skhan2523

    skhan2523

    Joined:
    May 26, 2016
    Posts:
    16
    Yes I have the same Issue it was working fine when I hard copied filename and data to save. But now when I am passing filename and data to save through a function it is not working. and not errors

    Code (CSharp):
    1. public static PlayServicesScript instance;
    2.     [SerializeField] Text test_dataText;
    3.     [SerializeField] Text test_dataStatusText;
    4.     void Awake()
    5.     {
    6.         if (instance == null)
    7.         {
    8.             instance = this;
    9.             DontDestroyOnLoad(this.gameObject);
    10.         }
    11.         else
    12.         {
    13.             Destroy(this.gameObject);
    14.         }
    15.  
    16.         try
    17.         {
    18.  
    19.             PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().EnableSavedGames().Build();
    20.             PlayGamesPlatform.InitializeInstance(config);
    21.             PlayGamesPlatform.DebugLogEnabled = true;
    22.             PlayGamesPlatform.Activate();
    23.  
    24.         }
    25.         catch (Exception exception)
    26.         {
    27.             Debug.Log(exception);
    28.         }
    29.     }
    30.  
    31.     public void SignIn(Action successCallback = null, Action errorCallback = null)
    32.     {
    33.         try
    34.         {
    35.             Social.localUser.Authenticate((bool success) =>
    36.             {
    37.                 if (success)
    38.                 {
    39.                     successCallback?.Invoke();
    40.                 }
    41.             });
    42.         }
    43.         catch (Exception e)
    44.         {
    45.             Debug.Log(e);
    46.             errorCallback?.Invoke();
    47.         }
    48.     }
    49.     public void SignOut()
    50.     {
    51.         if (Social.localUser.authenticated)
    52.         {
    53.             PlayGamesPlatform.Instance.SignOut();
    54.         }
    55.     }
    56.  
    57.     #region CLOUD_SAVE
    58.  
    59.     string saveStr;
    60.     string fileName;
    61.     public void SetFileName(string fName)
    62.     {
    63.         fileName = fName;
    64.     }
    65.  
    66.     private string GetFileName()
    67.     {
    68.         return fileName;
    69.     }
    70.  
    71.     private string GetStringToSave()
    72.     {
    73.         return saveStr;
    74.     }
    75.  
    76.     public void SetStringToSave(string str)
    77.     {
    78.         saveStr = str;
    79.     }
    80.  
    81.     private bool isSaving = false;
    82.     byte[] bData;
    83.  
    84.     public void OpenSave(bool saving)
    85.     {
    86.         if (Social.localUser.authenticated)
    87.         {
    88.             Debug.Log("Inside OpenSave()");
    89.             isSaving = saving;
    90.  
    91.             ((PlayGamesPlatform)Social.Active).SavedGame.OpenWithAutomaticConflictResolution("testit",
    92.                 DataSource.ReadCacheOrNetwork,
    93.                 ConflictResolutionStrategy.UseLongestPlaytime,
    94.                 SavedGameOpen);
    95.         }
    96.     }
    97.  
    98.     private void SavedGameOpen(SavedGameRequestStatus reqStatus, ISavedGameMetadata metadata)
    99.     {
    100.        
    101.         if (reqStatus == SavedGameRequestStatus.Success)
    102.         {
    103.             Debug.Log("Inside SavedGameOpen()");
    104.             if (isSaving)
    105.             {
    106.                 byte[] data = System.Text.ASCIIEncoding.ASCII.GetBytes(GetStringToSave());
    107.                 SavedGameMetadataUpdate metaDataUpdate = new SavedGameMetadataUpdate.Builder().WithUpdatedDescription("Saved at: " + System.DateTime.Now.ToString()).Build();
    108.                 ((PlayGamesPlatform)Social.Active).SavedGame.CommitUpdate(metadata, metaDataUpdate, data, SaveUpdate);
    109.             }
    110.  
    111.             else
    112.             {
    113.                 ((PlayGamesPlatform)Social.Active).SavedGame.ReadBinaryData(metadata, SaveRead);
    114.             }
    115.         }
    116.     }
    117.  
    118.     private void SaveUpdate(SavedGameRequestStatus reqStatus, ISavedGameMetadata metadata)
    119.     {
    120.         if (reqStatus == SavedGameRequestStatus.Success)
    121.         {
    122.             Debug.Log("Inside SaveUpdate()");
    123.             test_dataStatusText.text = "Saved Successfully";
    124.             Debug.Log("Saved Successfully");
    125.         }
    126.         else
    127.         {
    128.  
    129.             test_dataStatusText.text = "Saved Failed";
    130.             Debug.LogError("Saved Failed");
    131.         }
    132.     }
    133.  
    134.     private void SaveRead(SavedGameRequestStatus reqStatus, byte[] data)
    135.     {
    136.         if (reqStatus == SavedGameRequestStatus.Success)
    137.         {
    138.             Debug.Log("Inside SaveRead()");
    139.             test_dataText.text = System.Text.ASCIIEncoding.ASCII.GetString(data);
    140.             Debug.Log("Data: " + test_dataText.text);
    141.             test_dataStatusText.text = "Read Successfully";
    142.             Debug.Log("Read Successfully");
    143.         }
    144.         else
    145.         {
    146.             test_dataStatusText.text = "Read Failed";
    147.             Debug.LogError("Read Failed");
    148.         }
    149.     }
    150.  
    151.     #endregion
    The logcat show the following, no errors

    Code (CSharp):
    1. 03-08 22:37:28.441  5227  5255 I Unity   : Inside OpenSave()
    2. 03-08 22:37:28.441  5227  5255 I Unity   : UnityEngine.Logger:Log(LogType, Object)
    3. 03-08 22:37:28.441  5227  5255 I Unity   : PlayServicesScript:OpenSave(Boolean)
    4. 03-08 22:37:28.441  5227  5255 I Unity   : UnityEngine.Events.UnityAction:Invoke()
    5. 03-08 22:37:28.441  5227  5255 I Unity   : UnityEngine.Events.UnityEvent:Invoke()
    6. 03-08 22:37:28.441  5227  5255 I Unity   : UnityEngine.EventSystems.EventFunction`1:Invoke(T1, BaseEventData)
    7. 03-08 22:37:28.441  5227  5255 I Unity   : UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
    8. 03-08 22:37:28.441  5227  5255 I Unity   : UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
    9. 03-08 22:37:28.441  5227  5255 I Unity   : UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
    10. 03-08 22:37:28.441  5227  5255 I Unity   : UnityEngine.EventSystems.StandaloneInputModule:Process()
    11. 03-08 22:37:28.441  5227  5255 I Unity   :
     
  5. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
  6. skhan2523

    skhan2523

    Joined:
    May 26, 2016
    Posts:
    16
    @JeffDUnity3D I followed the same tutorial and now its working. No change I don't know what would have been the issue.
     
  7. mahito2932

    mahito2932

    Joined:
    Nov 15, 2020
    Posts:
    98
    Can you please show your working script, I have the same issues please.