playgameservices / play-games-plugin-for-unity

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

Save game not working! #3107

Closed Linux1230 closed 2 years ago

Linux1230 commented 2 years ago

Save game feature not working. I have enabled cloud save on the configuration page. I have configured the OAuth stuff in the cloud platform. I linked the application keys... image I have a green checkmark in the Google Play Games Configuration Menu image (Please ignore the language)

Google Play Games login is working correctly!

Code for initialization:

PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
                                                        .EnableSavedGames()
                                                        .Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();

I have found this in my adb logcat: Successfully found game: displayName [], applicationId [], packageName [] Game does not cloud save APIs. Skipping creation and connection to Internal Drive API

I deleted the application name from the log!

Code for Cloud save:

public override void SetGameProgress(GameProgress gameProgress, Action<SavingManagerResponseStatus> callback)
        {
            if (GPGSAuthentication.IsAuthenticated)
            {
                gameProgress.time = DateTime.Now;

                //local save without callback
                SetLocalValue(SavingManagerType.GameProgress, gameProgress.ToJson());

                PlayGamesPlatform.Instance.SavedGame.OpenWithAutomaticConflictResolution(fileName, DataSource.ReadCacheOrNetwork,
                    ConflictResolutionStrategy.UseLongestPlaytime, (status, metaData) => StartSaveGameProgress(status, metaData, gameProgress, callback));
            }
            else
                base.SetGameProgress(gameProgress, callback);
        }

        private void StartSaveGameProgress(SavedGameRequestStatus status, ISavedGameMetadata metaData, 
            GameProgress gameProgress, Action<SavingManagerResponseStatus> callback)
        {
            if (status == SavedGameRequestStatus.Success)
            {
                byte[] data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(gameProgress));
                var updateMeta = new SavedGameMetadataUpdate.Builder().Build();
                PlayGamesPlatform.Instance.SavedGame.CommitUpdate(metaData, updateMeta, data, (status, metaData) => EndGameProgress(status, metaData, callback));
            }
            else
                callback(SavingManagerResponseStatus.NetworkError);
        }

        private void EndGameProgress(SavedGameRequestStatus status, ISavedGameMetadata metaData, Action<SavingManagerResponseStatus> callback)
        {
            if (status == SavedGameRequestStatus.Success)
                callback(SavingManagerResponseStatus.Success);
            else
                callback(SavingManagerResponseStatus.NetworkError);
        }

Can someone please help me figure out what went wrong. Why the cloud save not working? It would be helpful to know if my code is bad or I missed something while configuring the play game project.

Additional info: Unity version: 2020.3.22f Plugin version: 0.10.13

ozdemir08 commented 2 years ago

Hi, could you capture a bug report and share with us? You can share it with a private Drive link and approve access only from ..@google.com accounts.

ozdemir08 commented 2 years ago

Also, could you try it with v10.14, importing the plugin after removing Plugins/ and GooglePlayGames/Plugins directories?

Linux1230 commented 2 years ago

Hi, thanks for your help! Here is the the link for the bug report

Linux1230 commented 2 years ago

I tried the 0.10.14 version and cloud save still not works, I see the same error in my logcat.

ozdemir08 commented 2 years ago

Thanks for the bug report. I can't see the relevant logs unfortunately. Could you capture another bug report right after you go through the same steps in your game? You can check if your logs have SignInPerformer or SignInManager first.

Linux1230 commented 2 years ago

Hi, thanks for the quick reply, here is a new bugreport in this I can see some lines with SignInPerformer-27 or SignInManagerV2.

Linux1230 commented 2 years ago

Hi, @ozdemir08 are there any news about this bug?

Xardas0327 commented 2 years ago

Hi @ozdemir08, We would like to release our game, and this is only, which is missing. Have you checked, which Linux1230 enclosed?

Linux1230 commented 2 years ago

Hi @ozdemir08, we created a new project and tested our configuration there as well, and we figured it out we have an PlayGamesPlatform.Instance call before our initialization in an if statement if (PlayGamesPlatform.Instance != null). And we found out this will initialize the instance with the Default Configuration and can't be overwriten with our one. We figured this out via viewing the plugin source code. This problem was not clear for us in the documentation, i think you can maybe add this as a warning.

olehkuznetsov commented 2 years ago

From plugin sources:

public static void InitializeInstance(PlayGamesClientConfiguration configuration) { if (sInstance == null || sInstance.mConfiguration != configuration) { sInstance = new PlayGamesPlatform(configuration); return; }

GooglePlayGames.OurUtils.Logger.w(
    "PlayGamesPlatform already initialized. Ignoring this call.");

}

It seems if configuration is different it still should reinitialize. Can you check if you see in log "PlayGamesPlatform already initialized. Ignoring this call.", pease?

Xardas0327 commented 2 years ago

that was our funtion:

 private void Init()
        {
           if(PlayGamesPlatform.Instance != null)
                 return;

            PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
                                                        .EnableSavedGames()
                                                        .Build();

            PlayGamesPlatform.InitializeInstance(config);
            PlayGamesPlatform.DebugLogEnabled = true;
            PlayGamesPlatform.Activate();
        }

After if, the return always run. But now we know, so we deleted the if form the beginning.

Linux1230 commented 2 years ago

We used this code and PlayGamesPlatform.DebugLogEnabled = true; was never called so we can't even saw all logs. So we defenitly writed a wrong code. And first of all it would be great if I post the hole class where the init code is. Sorry for wasting your time! And thanks for all the response we got!