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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Gamecenter social api not reporting achievement increments

Discussion in 'iOS and tvOS' started by SnowDaySoftware, Sep 24, 2014.

  1. SnowDaySoftware

    SnowDaySoftware

    Joined:
    Mar 25, 2013
    Posts:
    11
    I'm using the Social API with gamecenter and I am not able to get an incremental achievement to update properly. I have a simple achievement that is just "Play 5 Games" and I just try to do a ReportProgress by 20 to increase it by 20 so when it occurs 5 times, it will be 100% and will unlock. Am I not doing this correctly? Do I need to track the progress of the achievement completely within game? I'm even trying to get the current percentCompleted and adding 20 to that and it still is not updating progress. It gets the initial 20% increment but doesn't move from there, so I know that I am at least connecting correctly at some point. Here is what my code looks like, thanks for any help.

    Code (CSharp):
    1. Social.ReportProgress("1", 20.0, (boolsuccess) =>
    2. {
    3. if (success)
    4. {
    5.  
    6. }
    7. else
    8. {
    9.  
    10. }
    11. });
     
  2. PixelEnvision

    PixelEnvision

    Joined:
    Feb 7, 2012
    Posts:
    513
    I haven't tried it but as far as I know you'll need to pre-calc and submit the current percentage, it doesn't increment. So, when it's reached 40% try to report that directly...
     
  3. SnowDaySoftware

    SnowDaySoftware

    Joined:
    Mar 25, 2013
    Posts:
    11
    Thanks for the reply, I was wondering if that was the case. I put together this function to get the current percentage, does this not return what I am expecting it to? I only have an iOS 8 device and I've seen a couple things where people are having issue with the iOS8 sandbox so I'm not sure if its just me or what.

    Code (CSharp):
    1.     private double getAchievementProgress(string id)
    2.     {
    3.         double result = 0.0;
    4.         Social.LoadAchievements (achievements => {
    5.         if (achievements.Length > 0) {
    6.                 foreach (IAchievement achievement in achievements)
    7.                 {
    8.                     if(achievement.id == id){
    9.                         result = achievement.percentCompleted;
    10.                     }
    11.                 }
    12.             }
    13.         });
    14.         return result;
    15.     }
    16.  
    17. Social.ReportProgress(myAchievementID, getAchievementProgress(myAchievementID) + 20.0, (bool success) => //play 5 games(4th Liner)
    18.                                                                 {
    19.             if (success)
    20.             {
    21.             }
    22.             else
    23.             {
    24.             }
    25.         });
     
  4. Horror

    Horror

    Joined:
    Jul 18, 2011
    Posts:
    207
    Hi,

    Sorry to dig up a months old post but I'm currently having problems with the same thing. Did you ever find a solution to this?

    I just tried the same code that you are using and added a Debug.Log line to print the result of getAchievementProgress. The result is returned correctly but it seems to be returning it after ReportProgress has done its work and then failing because the new progress reported is lower than the previous.

    Is there a way to write the code so that it waits for the previous result to be returned from the server before submitting the new one? Or do you just have to ensure that you've retrieved the previous result well in advance?

    Cheers

    EDIT:

    Got it working with this way:

    Code (CSharp):
    1.         Social.LoadAchievements (achievements => {
    2.             if (achievements.Length > 0) {
    3.                 foreach (IAchievement achievement in achievements)
    4.                 {
    5.                     if(achievement.id == "CyborbsCyborbinator"){
    6.                         scoreCyborbinatorPrevious = achievement.percentCompleted;
    7.                         Debug.Log("CYBORBINATOR PERCENT RETURNED: " + scoreCyborbinatorPrevious);
    8.  
    9.                         Social.ReportProgress("CyborbsCyborbinator", (scoreCyborbinatorCurrent + scoreCyborbinatorPrevious), (bool successCyborbinator) => {
    10.                             if (successCyborbinator)
    11.                             {
    12.                                 Debug.Log("Reported CyborbsCyborbinator");
    13.                             }
    14.                             else
    15.                             {
    16.                                 Debug.Log("Failed CyborbsCyborbinator");
    17.                             }
    18.                         });
    19.                     }
    20.  
    21.                     if(achievement.id == "CyborbsSupercharged"){
    22.                         scoreSuperchargedPrevious = achievement.percentCompleted;
    23.                         Debug.Log("SUPERCHARGED PERCENT RETURNED: " + scoreSuperchargedPrevious);
    24.  
    25.                         Social.ReportProgress("CyborbsSupercharged", (scoreSuperchargedCurrent + scoreSuperchargedPrevious), (bool successSupercharged) => {
    26.                             if (successSupercharged)
    27.                             {
    28.                                 Debug.Log("Reported CyborbsSupercharged");
    29.                             }
    30.                             else
    31.                             {
    32.                                 Debug.Log("Failed CyborbsSupercharged");
    33.                             }
    34.                         });
    35.                     }
    36.                 }
    37.             }
     
    Last edited: Nov 26, 2014
    hdeekshith likes this.
  5. SnowDaySoftware

    SnowDaySoftware

    Joined:
    Mar 25, 2013
    Posts:
    11
    I had to calculate the next increment, like how you did. I don't think I could get the percent completed working so I just used PlayerPrefs to hold the achievement progress and then do the calculation based off that. Not as easy as google but i guess it still works.