1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. We want to know how you learned Unity! Help us by taking this quick survey and have a chance at a $25 gift card
    Dismiss Notice
  5. Are you an artist or level designer going to Unite Europe? Join our roundtables there to discuss artist features.
    Dismiss Notice
  6. Unity 5.6 is now released.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice

Problem with Game Center achievements

Discussion in 'Scripting' started by willchil, Mar 15, 2015.

  1. willchil

    willchil

    Joined:
    Mar 15, 2015
    Posts:
    3
    I'm trying to implement achievements in my iOS game using Game Center and the Social API. I have 6 achievements registered on iTunes Connect as can be seen in the image below. However, when I call Social.ReportProgress with the Achievement ID, progress percent, and callback, it always fails to report it successfully and logs the error "Achievement ID not found". I've noticed that while Social.LoadAchievements will return 0 results, Social.LoadAchievementDescriptions will return 3 descriptions named "Achievement01" etc.

    Here is my code:



    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using UnityEngine.SocialPlatforms;
    4. using UnityEngine.SocialPlatforms.GameCenter;
    5. using System.Collections;
    6.  
    7. public class GameCenter : MonoBehaviour {
    8.  
    9.     void Start () {
    10.         if(!Social.localUser.authenticated)
    11.             login ();
    12.         Social.ReportProgress("World1", 100, load);
    13.     }
    14.  
    15.     void login() {
    16.             if (success) {
    17.  
    18.                 //Log user information
    19.                 Debug.Log ("Authentication successful");
    20.                 string userInfo = "Username: " + Social.localUser.userName +
    21.                     "\nUser ID: " + Social.localUser.id +
    22.                         "\nIsUnderage: " + Social.localUser.underage;
    23.                 Debug.Log (userInfo);
    24.  
    25.                 //Log description information
    26.                 Social.LoadAchievementDescriptions (descriptions => {
    27.                     if (descriptions.Length > 0) {
    28.                         Debug.Log ("Got " + descriptions.Length + " achievement descriptions");
    29.                         string achievementDescriptions = "Achievement Descriptions:\n";
    30.                         foreach (IAchievementDescription ad in descriptions) {
    31.                             achievementDescriptions += "\t" +
    32.                                 ad.id + " " +
    33.                                     ad.title + " " +
    34.                                     ad.unachievedDescription + "\n";
    35.                         }
    36.                         Debug.Log (achievementDescriptions);
    37.                     }
    38.                     else
    39.                         Debug.Log ("Failed to load achievement descriptions");
    40.                 });
    41.  
    42.                 //Log achievement information
    43.                 Social.LoadAchievements (achievements => {
    44.                     if (achievements.Length == 0)
    45.                         Debug.Log ("Error: no achievements found");
    46.                     else
    47.                         Debug.Log ("Got " + achievements.Length + " achievements");
    48.                 });
    49.             }
    50.             else
    51.                 Debug.Log ("Authentication failed");
    52.         });
    53.     }
    54.  
    55.     void load(bool result){
    56.         if(result){
    57.             Debug.Log ("Successfully reported progress");
    58.         } else {
    59.             Debug.Log ("Failed to report progress");
    60.         }
    61.     }
    62. }

    I always seem to successfully login, but it doesn't know that my achievements are there. If anyone has more experience with the Social API, help would be greatly appreciated.
     

    Attached Files:

  2. brockemon

    brockemon

    Joined:
    Dec 21, 2012
    Posts:
    22
    I have the same issue. Working on it right now and looking for answers. Will keep you posted if I find answers somewhere else.
     
  3. HollowRockAdam

    HollowRockAdam

    Joined:
    Jan 15, 2013
    Posts:
    16
    Same problem here. If anyone finds a solution, please post it here. This is the only thing holding up the submission of my game and it is quite frustrating.
     
  4. willchil

    willchil

    Joined:
    Mar 15, 2015
    Posts:
    3
    I submitted my app to Apple without Game Center in this version. Considering all the examples and assets I saw did it the exact same way and also failed, I'm assuming it's a bug in the way Unity 5 handles Game Center in iOS 8.

    Prime31 makes a Game Center plugin, and their website notes that there is a bug with GameKit in Unity 5, but even after following their workaround, it still didn't work for me.
     
  5. HollowRockAdam

    HollowRockAdam

    Joined:
    Jan 15, 2013
    Posts:
    16
    I also have an asset in the Asset Store for Game Center. It is actually the #1 search result for game center: https://www.assetstore.unity3d.com/en/#!/content/16887

    Obviously, this is extremely frustrating in regard to my own games, and for people who buy my asset. I really hope this gets fixed asap =/
     
  6. HollowRockAdam

    HollowRockAdam

    Joined:
    Jan 15, 2013
    Posts:
    16
    Oh also - It is actually not just in regard to iOS 8. My iPod Touch 5th gen is running iOS 7 with the same result.
     
  7. brockemon

    brockemon

    Joined:
    Dec 21, 2012
    Posts:
    22
    Just to verify with you guys.

    If I call Social.LoadAchievementDescriptions I get a listing with all of my achievements as I have configured them on Itunes Connect with correct Id's.

    So this shows that the achievements have been setup on the servers correctly.

    It is just when I call ReportProgress with those same Id's things return a failed result.
     
  8. brockemon

    brockemon

    Joined:
    Dec 21, 2012
    Posts:
    22
    Looking at the console output from xcode. I get something that looks like this when I try to ReportProgress.

    Looking for CgkIuLudmpkHEAIQCw, cache count is 0
    Unlock result: False



     
  9. HollowRockAdam

    HollowRockAdam

    Joined:
    Jan 15, 2013
    Posts:
    16
    Correct. On my end, what I am seeing is this:

    -I can open and view GC correctly inside the game
    -Leaderboards work perfectly, and scores are reporting correctly
    -I can correctly see a list of all achievements in GC, however:
    -I cannot report an achievement correctly. It always returns false, no matter what

    Anyone made any progress?
     
    Lee_Sin likes this.
  10. brockemon

    brockemon

    Joined:
    Dec 21, 2012
    Posts:
    22
    Not yet. I am trying to find a way to receive the error message instead of a true/false value.
     
  11. HollowRockAdam

    HollowRockAdam

    Joined:
    Jan 15, 2013
    Posts:
    16
    Same here - I will make sure to post if I succeed.
     
  12. brockemon

    brockemon

    Joined:
    Dec 21, 2012
    Posts:
    22
    Can't figure out how to run the debugger on the native DLL running the Game Center code.... Sort of stuck at this point.
     
  13. HollowRockAdam

    HollowRockAdam

    Joined:
    Jan 15, 2013
    Posts:
    16
    I'm stuck at the same point, which is unfortunate. My game just reached 100k downloads and I have been preparing a giant update adding a lot of features and play modes as the game just keeps getting lots of downloads.

    I guess I will just submit without achievements for now. This is disappointing as the new update has a virtual currency (gold) that the player uses to unlock different weapons. Unlocking each weapon completes an achievement. When the user uninstalls the game and then re-installs it later - if that achievement is complete then their weapon is once again unlocked. I use this method instead of keeping up with user accounts and player unlock progression on my own server.

    Ah well... I'll just get another update out as soon as Unity fixes this. Aside from this issue, I am quite loving Unity 5. Good job Unity team =)

    But please get this fixed ASAP! =D
     
  14. Dreeka

    Dreeka

    Joined:
    Jul 15, 2010
    Posts:
    499
    Is there any progress on this issue?
     
  15. brockemon

    brockemon

    Joined:
    Dec 21, 2012
    Posts:
    22
    Hey,

    In the end I switched to using the Prime31 Gamecenter plugin https://prime31.com/docs#iosGameCenter

    Everything worked after this without any changes to Itunes Connect.

    I am guessing there is a bug in the Unity built in stuff.
     
  16. bufbot

    bufbot

    Joined:
    Nov 18, 2014
    Posts:
    2
    I have the same frustrating issue here,

    I can get the listing of all my achievements without issues but I am unable to get Social.LoadAchievements to work at all, is there any hope that this will be fixed soon or someone will find a fix ?
     
  17. brockemon

    brockemon

    Joined:
    Dec 21, 2012
    Posts:
    22
    I just said if you use the Prime31 Gamecenter plugin you can get achievements to work. Read the whole thread.
     
  18. bufbot

    bufbot

    Joined:
    Nov 18, 2014
    Posts:
    2
    I read the whole thread and the whole point is to be able to use an actual feature from the engine, not to have to use a costly third party plugin that will do the exact same thing.
     
  19. brockemon

    brockemon

    Joined:
    Dec 21, 2012
    Posts:
    22
    Just so you know bufbot. The expensive plugin isn't exactly the same as the built in. It is a lower level API and you can get a bit more debug error info back if you are having issues.

    But yes it would be nice if the builtin stuff works. Bit dissapointing.
     
  20. litebox

    litebox

    Joined:
    Aug 29, 2011
    Posts:
    102
    I have the same issue, even after update to Unity 5.0.1, after report progress returns false and I get log:

    Looking for CgkI97W8sPQTEAIQBA, cache count is 1

    Have anybody found a workaround?
     
  21. litebox

    litebox

    Joined:
    Aug 29, 2011
    Posts:
    102
    After a few days of pain and sorrow I figured it out: it's not a bug of Unity or Game Center.
    Sandbox transactions have a very low priority against the production games functionality, so in the "rush hour" I can't send any achievement and always get a message "cache count is X", but if you try to test achievements at night, then all is working good.
    I think when I push my game to production achievements will be processing all time.
     
  22. Squarehead

    Squarehead

    Joined:
    Sep 18, 2014
    Posts:
    10
    I am experiencing the same problem. Can anyone confirm if this is a Unity or Sandbox server issue?
     
  23. namine

    namine

    Joined:
    Mar 1, 2013
    Posts:
    21
    Tried it for a few days now and never got it worked. If Prime31 works all the time that can't be a server issue
     
  24. marcpeyre

    marcpeyre

    Joined:
    Jan 23, 2014
    Posts:
    5
    I can confirm the above issues while using Unity 5.0.1. I can login and get the achievement descriptions, but I never succeeded in reporting an achievement. I'm now trying to change to the native iOS API to see if I can get that to work properly.
     
  25. namine

    namine

    Joined:
    Mar 1, 2013
    Posts:
    21
    Thanks everyone, let's hope Unity will provide a fix soon.
     
  26. marcpeyre

    marcpeyre

    Joined:
    Jan 23, 2014
    Posts:
    5
    I've spent the last two days figuring out how to make a Native iOS Plugin for Unity and I've almost succeeded. I can now successfully report an achievement with game center banner. I'm cleaning up the code now and I'll post the plugin here tonight or tomorrow for you guys to use. It only replaces the Social.ReportAchievement method with a working method, so you can still use all other Social API related code.
     
    namine likes this.
  27. marcpeyre

    marcpeyre

    Joined:
    Jan 23, 2014
    Posts:
    5
    Here it is!

    1) Place the contents of the attached .rar in Assets/Plugins/iOS
    2) Add the following code to your script that would normally call Social.ReportProgress()

    Code (CSharp):
    1. [DllImport("__Internal")]
    2. private static extern void _ReportAchievement( string achievementID, float progress );
    3) Make sure your library and header search paths in your xcode build settings direct to $(SRCROOT)/Libraries/Plugins/iOS
    My paths has some wrong backslashes by default, so I have to change them every time I want to archive the project.

    Hope this works for everyone!

    PS: If anyone wants to extend this plugin, let me know so I can send you the xcode project of the plugin.
     

    Attached Files:

    Last edited: Apr 23, 2015
  28. PlayKiseki

    PlayKiseki

    Joined:
    Oct 4, 2014
    Posts:
    14
    marcpeyre,

    You are absolutely, 100% THE MAN. I used your solution and it worked first time with NO errors or anything. I've been stuck on this for a whole week trying to get achievements to work, and now I can finally continue with the development of my game. THANK YOU!
     
    marcpeyre likes this.
  29. Diekeke

    Diekeke

    Joined:
    Jul 9, 2012
    Posts:
    4
    When I try to add the code I get these errors:

    -Assets/Achievements.cs(38,10): error CS0246: The type or namespace name `DllImport' could not be found. Are you missing a using directive or an assembly reference?

    -Assets/Achievements.cs(38,10): error CS0246: The type or namespace name `DllImportAttribute' could not be found. Are you missing a using directive or an assembly reference?

    Also, I don't see a dll file in the .rar, I only get GCNative.h, GCNative_Bridge.h and libGCNative.a
    Could you please guide me here?:p
    Thanks.
     
  30. PlayKiseki

    PlayKiseki

    Joined:
    Oct 4, 2014
    Posts:
    14
    Diekeke,

    Make sure you add

    Code (csharp):
    1. using System.Runtime.InteropServices;
    at the top of your script. Then, paste the two lines marcpeyre posted somewhere in your script and call replace your usual "Social.ReportProgress" code with

    Code (csharp):
    1. _ReportAchievement("yourAchievementID", 100.0f);
    EDIT: Here's how I implemented this fix easily so that I can use it in any other script. All of my 10 achievements are now working flawlessly! Create a new .cs script "achievements.cs" and delete everything in there. Paste the below script into it:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Runtime.InteropServices;
    4.  
    5. public static class achievements{
    6.  
    7.  
    8. [DllImport("__Internal")]
    9. public static extern void _ReportAchievement( string achievementID, float progress );
    10.  
    11. }
    Then, super easy, report your achievements from any script with the following code:

    Code (csharp):
    1. achievements._ReportAchievement("yourAchievementID", 100.0f);
    Done! Super easy. Thanks again Marc for this awesome fix!
     
    Last edited: Apr 25, 2015
    devoks, josec89, DennG and 3 others like this.
  31. Diekeke

    Diekeke

    Joined:
    Jul 9, 2012
    Posts:
    4
    Awesome! It works perfectly, thank you:)
     
    PlayKiseki likes this.
  32. namine

    namine

    Joined:
    Mar 1, 2013
    Posts:
    21
    Working great, thanks ! One question, is it possible to get achievements images on banners instead of GC generic's one ?
     
  33. litebox

    litebox

    Joined:
    Aug 29, 2011
    Posts:
    102
    Yes, it's definitely a Unity bug, on production I experience same behavior: some how from time to time achievements is working, but must of the time - not.
     
  34. kreso

    kreso

    Joined:
    Sep 7, 2013
    Posts:
    54
    I made a report with Unity. Case number 693822.
     
  35. cb31416

    cb31416

    Joined:
    Nov 4, 2013
    Posts:
    7
    I have the same problem
    Code (CSharp):
    is not working when trying to submit achievement progress on IOS, it always returns false twice.

    This was working on an older version of Unity, but it's not working on Unity 5 version 5.0.1f1

    This was working on the first version of my game, I updated my game once before and everything was working (including achievements).

    I just released a new version of my game and unfortunately I didn't test achievements before submitting the game to Apple since on my previous game update everything worked fine.

    My game is now live on the AppStore, but achievements are not working. I just tested achievements on Game Center Sandbox, and they are not working either.

    BTW my game is this one Earth Assault

    Just like @HollowRockAdam
    -I can open and view GC correctly inside the game
    -Leaderboards work perfectly, and scores are reporting correctly
    -I can correctly see a list of all achievements in GC, however:
    -I cannot report an achievement correctly. It always returns false twice.

    Does anybody know if Unity has confirmed this a s a bug/problem?
     
  36. cb31416

    cb31416

    Joined:
    Nov 4, 2013
    Posts:
    7
    Hello @marcpeyre, could you share the Xcode project of the plugin?
    I would really appreciate it.
    Thanks
     
    TheSlayerNo1 likes this.
  37. seejay3061

    seejay3061

    Joined:
    Oct 21, 2013
    Posts:
    12
    I have had success using @marcpeyre 's code/plugin and @PlayKiseki 's implementation from above. Thanks so much guys!

    I just wanted to note for anyone as novice as myself (sorry if this is obvious):
    Once I added the files to unity, implemented and built, I initially got 3 errors in Xcode resulting in a failure. I found that I had to click on each of the 3 imported files from @marcpeyre and check off GameKit for PlatformSettings/Framework dependencies in the inspector. Once I did this, I built again and had no errors.

    Thanks
     
  38. litebox

    litebox

    Joined:
    Aug 29, 2011
    Posts:
    102
    dfjhde likes this.
  39. DennG

    DennG

    Joined:
    Dec 5, 2013
    Posts:
    158
  40. JanduSoft

    JanduSoft

    Joined:
    Mar 14, 2014
    Posts:
    8
    My solution was to put this code before initializing the social local user.

    Code (CSharp):
    1.  
    2.         #if UNITY_IOS
    3.         #endif
    4.  
    5.         // Authenticate and register a ProcessAuthentication callback
    6.         // This call needs to be made before we can proceed to other calls in the Social API
    7.         Social.localUser.Authenticate (ProcessAuthentication);
     
  41. filler03

    filler03

    Joined:
    Jul 27, 2011
    Posts:
    2
    I have implemented this like you said, but when I try to build in xcode I get the following error:

    Undefined symbols for architecture armv7:
    "__ReportAchievement", referenced from:
    RegisterMonoModules() in RegisterMonoModules.o
    ld: symbol(s) not found for architecture armv7
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
     
  42. warchild14

    warchild14

    Joined:
    Apr 5, 2014
    Posts:
    6
    Thanks marcpeyre
    I will try your plugin.

    May 29 the problem still happening.
    Using Unity 5.0.2f1, testing on iOS8

    Also I gave a quick look on the patch releases and don't find anything about it yet.


    Another thing:
    Pardon my noob side, I'm using the google play games plugin and it uses the same
    "Social.ReportProgress" isn't? Is is bugged too?
    I always have trouble finding android devices to test :~

    the marc plugin is just for iOS, isnt?
    If for google play is ok [anybody can give a shout about this?], should i do something like this:

    Code (CSharp):
    1. #ifUNITY_IPHONE
    2. [DllImport("__Internal")]
    3. private static extern void _ReportAchievement( string achievementID, float progress );
    4.  
    5. #endif
    6. #ifUNITY_ANDROID
    7. Social.ReportProgress (toA, 100.0f, success => {
    8. Debug.Log(success ? "Reported achiev successfully" : "Failed to report achiev");
    9. });
    10. #endif
     
  43. kreso

    kreso

    Joined:
    Sep 7, 2013
    Posts:
    54
    Yes @warchild14 , as far as I can tell problem is only with Game Center (iOS). GPGS achievements work just fine.
     
    warchild14 likes this.
  44. warchild14

    warchild14

    Joined:
    Apr 5, 2014
    Posts:
    6
    Tested marcpeyre plugin, works like a charm - with the banner and everything else.

    But on Unity I keep getting this red warning in the final of the building:

    But testing on xcode after the building apparently worked out well.
     
  45. Brainversation01

    Brainversation01

    Joined:
    May 25, 2015
    Posts:
    15
  46. Maha-Ragab

    Maha-Ragab

    Joined:
    Jun 9, 2015
    Posts:
    1
    Thank you so much @marcpeyre !!!! It is so helpful :)
     
  47. warchild14

    warchild14

    Joined:
    Apr 5, 2014
    Posts:
    6

    about the warning: it vanished when restarted Unity - just like that. x)
    Everything is ok.
     
  48. Ox_

    Ox_

    Joined:
    Jun 9, 2013
    Posts:
    93
    I'm using Prime31 plugin and it mirrors Apple's GameKit with GameCenterAchievement and GameCenterAchievementMetadata classes.

    If the player has no achievements unlocked then achievementsLoadedEvent will return List with zero length! Also this event is called twice (at least in Sandbox mode) and the first call is always has empty List<GameCenterAchievement>.

    But achievementMetadataLoadedEvent returns all achievement descriptions properly.

    So there's no single GameCenterAchievement if the player had not achieved anything. Look into GameCenterAchievementMetadata.
     
  49. z37

    z37

    Joined:
    Feb 13, 2014
    Posts:
    29
    @PlayKiseki I did everything like you said with @marcpeyre files, but i get an error when reporting achievement in Unity Editor
    EntryPointNotFoundException: _ReportAchievement

    But on a device everything works good, thank you guys for your solution.
     
  50. warchild14

    warchild14

    Joined:
    Apr 5, 2014
    Posts:
    6
    I guess the error in editor is somehow expected. I've just 'commented' the method content while testing on editor to prevent odd behaviour.