Search Unity

Google play not opening Leaderboards and Achievements UI

Discussion in 'Scripting' started by DarkBladeNemo, Oct 4, 2017.

  1. DarkBladeNemo

    DarkBladeNemo

    Joined:
    Aug 23, 2013
    Posts:
    116
    Hi,

    So I am not sure if this is suppose to go here or in the Android section.

    Anywho my problem at the moment is my leaderboards and achievement ui are not opening when I press the button on my app. The app is published and the achievements do unlock so I know the sign in and so on is working.

    Code (CSharp):
    1. public void OpenLeaderboardsScore()
    2.     {
    3.         if (Social.localUser.authenticated)
    4.         {
    5.             ((PlayGamesPlatform)Social.Active).ShowLeaderboardUI (LEADERBOARDS_SCORE);
    6.         }
    7.     }
    Code (CSharp):
    1.  public void OpenAchievements()
    2.     {
    3.         if (Social.localUser.authenticated)
    4.         {
    5.             ((PlayGamesPlatform)Social.Active).ShowAchievementsUI ();
    6.         }
    7.     }
    I have looked at different variations of the codes used and tried them all but still not luck.
    Any help would be appreciated.

    Note the methods tried before:

    Code (CSharp):
    1.     PlayGamesPlatform.Instance.ShowLeaderboardUI ();
    2.                 PlayGamesPlatform.Instance.ShowAchievementsUI ();
    3.                 Social.ShowAchievementsUI ();
    4.                 Social.ShowLeaderboardUI ();
    5.  
     
  2. DarkBladeNemo

    DarkBladeNemo

    Joined:
    Aug 23, 2013
    Posts:
    116
  3. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    Looking at some of my code I see a few differences, but it should still work.

    Try this
    Code (CSharp):
    1. if (Social.Active.localUser.authenticated)
    2. {
    3.      Social.ShowLeaderboardUI();
    4.      Social.ShowAchievementsUI();
    5. }
    6.  
    Maybe the "Active" might make the difference(with the check if the user is authenticated). I am using Social.Active throughout my code and I have no issues.
     
  4. DarkBladeNemo

    DarkBladeNemo

    Joined:
    Aug 23, 2013
    Posts:
    116
    Awesome ill give it a swing when I get home later today. This has really been annoying me.

    Ill let you know how it goes. Thank you
     
  5. DarkBladeNemo

    DarkBladeNemo

    Joined:
    Aug 23, 2013
    Posts:
    116
    Okay so I changed it but it still isnt working. It logs in perfectly so I know that is working because it gives the little popup and allows for achievements to be unlocked.


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using GooglePlayGames;
    4. using GooglePlayGames.BasicApi;
    5. using UnityEngine.SocialPlatforms;
    6.  
    7. public class GooglePlayServiceManager : MonoBehaviour {
    8.  
    9.     public static GooglePlayServiceManager instance;
    10.  
    11.     [SerializeField] private string LEADERBOARDS_SCORE = "";//menu button not included you can add yours
    12.     [SerializeField]
    13.     private static string FirstTaste = ""; //change this keys depending on yours
    14.     [SerializeField]
    15.     private static string GBaT = "";
    16.     [SerializeField]
    17.     private static string Unstoppable = "";
    18.     [SerializeField]
    19.     private static string Master = " ";
    20.     [SerializeField]
    21.     private static string SweetTooth = "";
    22.     [SerializeField]
    23.     private static string CandyHoarder = "";
    24.     [SerializeField]
    25.     private static string GoingAllOut = "";
    26.  
    27.     private string[] achievements_names = { FirstTaste, GBaT, Unstoppable, Master, SweetTooth, CandyHoarder, GoingAllOut };
    28.  
    29.     private bool[] achievements;
    30.  
    31.     void Awake()
    32.     {
    33.         MakeInstance();
    34.     }
    35.  
    36.     void MakeInstance()
    37.     {
    38.         if (instance != null)
    39.         {
    40.             Destroy(gameObject);
    41.         }
    42.         else
    43.         {
    44.             instance = this;
    45.             DontDestroyOnLoad(gameObject);
    46.         }
    47.     }
    48.  
    49.     void InitializeAchievements()
    50.     {
    51.         achievements = GameController.instance.achievements;
    52.  
    53.         for (int i = 0; i < achievements.Length; i++)
    54.         {
    55.             if (!achievements[i])
    56.             {
    57.                 //achivement changes
    58.                 Social.ReportProgress(achievements_names[i], 0.0f, (bool success) => {
    59.                     //handle success
    60.                 });
    61.             }
    62.         }
    63.     }
    64.  
    65.     // Use this for initialization
    66.     void Start ()
    67.     {
    68.             PlayGamesPlatform.Activate();
    69.             Social.localUser.Authenticate((bool success) =>
    70.             {
    71.                 if (success)
    72.                 {
    73.                     InitializeAchievements();
    74.                 }
    75.             });
    76.     }
    77.  
    78.     void OnLevelWasLoaded()
    79.     {
    80.         CheckIfAnyUnlockedAchievements();
    81.         ReportScore(GameController.instance.hiScore);
    82.     }
    83.  
    84.     //use for button
    85.     public void OpenLeaderboardsScore()
    86.     {
    87.         if (Social.Active.localUser.authenticated)
    88.         {
    89.             Social.ShowLeaderboardUI();
    90.         }
    91.     }
    92.  
    93.     void ReportScore(int score)
    94.     {
    95.         if (Social.localUser.authenticated)
    96.         {
    97.             Social.ReportScore(score, LEADERBOARDS_SCORE, (bool success) => { });
    98.         }
    99.     }
    100.  
    101.     //use for button
    102.     public void OpenAchievements()
    103.     {
    104.         if (Social.Active.localUser.authenticated)
    105.         {
    106.             Social.ShowAchievementsUI();
    107.         }
    108.     }
    109.  
    110.     void UnlockAchievements(int index)
    111.     {
    112.         if (Social.localUser.authenticated)
    113.         {
    114.             //achievement change
    115.             Social.ReportProgress(achievements_names[index], 100.0f, (bool success) =>
    116.             {
    117.                 if (success)
    118.                 {
    119.                     achievements[index] = true;
    120.                     GameController.instance.achievements = achievements;
    121.                     GameController.instance.Save();
    122.                 }
    123.             });
    124.         }
    125.     }
    126.  
    127.     void CheckIfAnyUnlockedAchievements()
    128.     {
    129.         //we check if GameController is present
    130.         if (GameController.instance != null)
    131.             {
    132.                 //then we check if our score is greater than of equal to 20
    133.             if (GameController.instance.currentScore >= 1)
    134.                 {
    135.                     //then we check if our 1st achievement is unlocke or not
    136.                 if (!achievements[0])
    137.                     {
    138.                         //if not then we check if player is logged in
    139.                     if (Social.localUser.authenticated)
    140.                         {
    141.                             //then we unlock the achievement
    142.                             UnlockAchievements(0);
    143.                         }
    144.                     }
    145.                 }
    146.             }//Achievement 0
    147.  
    148.  
    149.     //    we check if GameController is present
    150.         if (GameController.instance != null)
    151.             {
    152.               //then we check if our score is greater than of equal to required score
    153.             if (GameController.instance.currentScore >= 10)
    154.                 {
    155.                     //then we check if our 2nd achievement is unlocke or not
    156.                 if (!achievements[1])
    157.                     {
    158.                         //if not then we check if player is logged in
    159.                     if (Social.localUser.authenticated)
    160.                         {
    161.     //                        then we unlock the achievement
    162.                            UnlockAchievements(1);
    163.                         }
    164.                     }
    165.                 }
    166.             }//Achievement 1
    167.  
    168.  
    169.     //    we check if GameController is present
    170.         if (GameController.instance != null)
    171.             {
    172.     //            then we check if our score is greater than of equal to required score
    173.             if (GameController.instance.currentScore >= 20)
    174.                 {
    175.     //                then we check if our 3rd achievement is unlocke or not
    176.                 if (!achievements[2])
    177.     //                {
    178.     //                    if not then we check if player is logged in
    179.                     if (Social.localUser.authenticated)
    180.                         {
    181.     //                        then we unlock the achievement
    182.                             UnlockAchievements(2);
    183.                         }
    184.                     }
    185.             }//Achievement 2
    186.         //    we check if GameController is present
    187.         if (GameController.instance != null)
    188.         {
    189.             //            we check if 1st 2 ships are unlocked
    190.             if (GameController.instance.currentScore >= 50)
    191.             {
    192.                 //                then we check if our 4th achievement is unlocke or not
    193.                 if (!achievements[3])
    194.                 {
    195.                     //                    if not then we check if player is logged in
    196.                     if (Social.localUser.authenticated)
    197.                     {
    198.                         //                        then we unlock the achievement
    199.                         UnlockAchievements(3);
    200.                     }
    201.                 }
    202.             }
    203.  
    204.         }//Achievement 3
    205.  
    206.  
    207.         //    we check if GameController is present
    208.         if (GameController.instance != null)
    209.         {
    210.             //            then we check if all ships are unlocked
    211.             if (GameController.instance.currentScore >= 100)
    212.             {
    213.                 //                then we check if our 5th achievement is unlocke or not
    214.                 if (!achievements[4])
    215.                 {
    216.                     //                    if not then we check if player is logged in
    217.                     if (Social.localUser.authenticated)
    218.                     {
    219.                         //                        then we unlock the achievement
    220.                         UnlockAchievements(4);
    221.                     }
    222.                 }
    223.             }
    224.         }//Achievement 4
    225.  
    226.         //    we check if GameController is present
    227.         if (GameController.instance != null)
    228.         {
    229.             //            then we check if all ships are unlocked
    230.             if (GameController.instance.currentScore >= 150)
    231.             {
    232.                 //                then we check if our 5th achievement is unlocke or not
    233.                 if (!achievements[5])
    234.                 {
    235.                     //                    if not then we check if player is logged in
    236.                     if (Social.localUser.authenticated)
    237.                     {
    238.                         //                        then we unlock the achievement
    239.                         UnlockAchievements(5);
    240.                     }
    241.                 }
    242.             }
    243.         }//Achievement 5
    244.  
    245.         //    we check if GameController is present
    246.         if (GameController.instance != null)
    247.         {
    248.             //            then we check if all ships are unlocked
    249.             if (GameController.instance.currentScore >= 200)
    250.             {
    251.                 //                then we check if our 5th achievement is unlocke or not
    252.                 if (!achievements[6])
    253.                 {
    254.                     //                    if not then we check if player is logged in
    255.                     if (Social.localUser.authenticated)
    256.                     {
    257.                         //                        then we unlock the achievement
    258.                         UnlockAchievements(6);
    259.                     }
    260.                 }
    261.             }
    262.         }//Achievements end
    263.             }
    264.  
    265.     }
    266.  
    267.  
    The entire script I use to run the login, achievements and leaderboard. Obviously I removed the achievement and leaderboard keys because apparently it is not a good idea to put them out on the internet.

    Can you have a look and see if I am doing something wrong or if it just takes awhile to activate?
    I appreciate the help.
     
  6. SD2020_

    SD2020_

    Joined:
    Nov 3, 2015
    Posts:
    107
    I had the same problem, are you building directly to your phone or is the game on the app store already?
     
  7. SD2020_

    SD2020_

    Joined:
    Nov 3, 2015
    Posts:
    107
    I'm just going to bed Private Message me.
     
  8. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    It seems fine. Make sure everything is setup correctly with GPGS in the editor. Also make sure everything is setup correctly in the Developer Console. If anything is out of wack it will fail. If the keystore doesn't match, any little discrepancy and it will fail.
     
  9. DarkBladeNemo

    DarkBladeNemo

    Joined:
    Aug 23, 2013
    Posts:
    116
    Been using the same Keystore and everything seems fine in the console. I have looked at several tutorials about the GPGS editor and followed along and that seems to be correct aswell. I figure if anything was out of wack none of the google play things would work.
     
  10. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    I have no idea what to tell you other than, it could be somewhere else in the code. Whenever I have a problem that the code looks fine for, I find that I did something somewhere else that was causing the problem. Its harder to debug on the device, but its gotta be done.