Google Play Achievements won't unlock when running on Android

Hello,

I just added some Google Play achievements to my game yesterday, and I’m really hoping the solution to this is something simple like “wait for Google to sync” or something, even though the app and the achievements are all published.

So, as the title says, the achievements simply won’t unlock in Google Play. The conditions which unlock them are definitely running, because the in-game visuals are working fine, but the Google Play parts just won’t unlock the achievement, even though they’re running in the same (working) functions.

These are some of the scripts I’ve made which affect the GPGS achievements:

Condition that should unlock the achievement:

if (PlayerPrefs.GetInt("Achievement1") >= 1)        //If Achievement 1 has been unlocked
        {
            progressCount += 1;     //Increase the progress count by 1
            achievement1Lock.SetActive(false);      //Remove the padlock
            achievementManager.UnlockAchievement(GPGSIds.achievement_the_first_night);        //Grant the achievement in Google Play
        }
        else    //If the Achievement has NOT been unlocked
            achievement1Txt.text = "????";      //Don't show the achievement's title

Function that should unlock the achievement:

public void UnlockAchievement(string _achievement)      //Function for unlocking an Achievement
    {
        Social.ReportProgress(_achievement, 100.0f, (bool success) =>
        {
            if (success)        //If the achievement is successfully granted
            {
                Debug.Log(_achievement + ": " + success.ToString());     //Report the achievement's success
            }
            else        //If the achievement fails to be granted (i.e. no internet, not logged in, etc)
            {
                Debug.Log(_achievement + ": " + success.ToString());     //Report the achievement's failure -- NOTE that the 'success' value is taken from the achievement set up's settings, so should return as 'failed' here
            }
        });
    }

These are just samples that should run to unlock the first achievement. I’ve set it up so that even if it didn’t unlock the first time (in case the player was offline or something), they won’t have to redo the achievement, and it will unlock when they view the in-game achievement list (which the first sample is taken from, as the PlayerPref value of “Achievement1” will always be 1 once the achievement should be unlocked).

Really hoping I can get by this, as everything else involved with these functions work except the stuff related to Google Play. As far as I can see, there’s no errors in the code or anything else.

Thanks in advance.

You need to check the device logs. You can just use adb logcat or Unity’s Android Logcat Package.

If the unlock is really executed, you’re likely getting an error message explaining what is going wrong. Setting up Google Play achievements is pretty involved and there’s a lot that can go wrong/missed, you really need to know what exactly isn’t working (e.g. could project setup, credentials setup, testing setup etc).

How do I used logcat on a project that’s being uploaded directly into open testing?

Ever since I added IAP to my project, I wasn’t able to upload the apk directly to my phone with Unity anymore, and have had to do it through uploading test builds to the Google Play console.

Logcat gives you the messages of all applications on the device, it doesn’t matter if your app is installed locally or through Google Play.

You might first want to upload a debug build for better stack traces or to include the Unity Logcat package in the build.

I already have Android Logcat installed in the editor:

Unless there’s something else I needed to do, I would assume it’s already included in the build, if it’s something that happens automatically if I’m using the package.

Or are you talking about a Logcat I can access on the Android device itself? I’ve only ever used Logcat when running the game while the device was hooked to my computer, and saw the logcat messages in the Unity editor itself.

Ah, right, Android Logcat is an editor-only package, there’s nothing to include in the build.

You should be able to use it to connect to your device, then open the build you’ve downloaded from Google Play on the device, and you should be able to see its log messages.

Ok, here’s what I got:

So, it says, “Must authenticate first”? I always got a similar error running my game in the Unity editor, but I always assumed that was due to Unity’s editor not being logged into Google Play, for obvious reasons, hence why I felt the need to test it on my Android device.

Why am I getting this message when running on the phone then? I do get the “Welcome User” message at the top every time I open the game, which tells me I’m being logged in (it even appears when I’m offline). Is this Google Play needing to validate the newly created achievements or something? They’re already displayed when I enter the Play Games app and view the achievements for my game. Or am I missing something?

EDIT: Thought it’s important to mention that the scene I’m loading should unlock the achievements automatically, seeing as I have a PlayerPref controlling them (so players don’t have to redo achievements if they’re playing offline, etc – they can just get them the next time they go online and view the in-game achievement page).

The error is coming from Unity’s Social API itself, so I would assume that Social.localUser.Authenticate hasn’t been called, hasn’t completed, or encountered an error.

Make sure you check the success argument in the callback and use the overload that also gives you an error string, which should tell you what is going wrong.

I got the achievements to unlock, finally. Seemed I needed to call PlayGamesPlatform.Activate() beforehand. Surprised the tutorials I followed got away without it.

1 Like