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. Dismiss Notice

GameCenter Plugin Live! Leaderboards and Achievements!

Discussion in 'iOS and tvOS' started by prime31, Sep 6, 2010.

  1. OceanBlue

    OceanBlue

    Joined:
    May 2, 2013
    Posts:
    251
    I'm having the same issue. This was working, now during testing tonight we've found it's not... and we have never touched the code since it was last tested as functioning. Has something changed on Apple's end Prime?

    Our issue is that during reporting a part % of completion, it's not adding to the figure that's already been reported. This used to work fine as I said above.

    I'm also getting my completed achievements reporting again as unlocked over and over. This never happened before either. Something must have changed on the game centre end for apple???
     
    Last edited: Sep 20, 2013
  2. OceanBlue

    OceanBlue

    Joined:
    May 2, 2013
    Posts:
    251

    @contract take a look at my blog where I have a walkthrough on setting up game center. Hope it helps http://cooloceans.wordpress.com/2013/05/16/prime31-game-center-plug-in-set-up/
     
  3. Contract-killer

    Contract-killer

    Joined:
    Sep 21, 2012
    Posts:
    42
    HI Prime31,
    I am trying to do the same app is getting crashed when I was just calling single function.

    if(GameCenterBinding.isPlayerAuthenticated() == false){
    GameCenterBinding.authenticateLocalPlayer();
    }
    GameCenterMultiplayerBinding.showMatchmakerWithMinMaxPlayers(2, 2);
     
  4. Contract-killer

    Contract-killer

    Joined:
    Sep 21, 2012
    Posts:
    42
    hi Prime
    if( bottomLeftButton( "Load Multiplayer Scene (Requires Multiplayer Plugin!)", 340 ) )
    {
    Application.LoadLevel( "GameCenterMultiplayerTestScene" );
    }
    this scene is also not available in the plugin ?
     
  5. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @contract, you can't just call authenticate and then immediately show the matchmaker. That won't work. You cannot show the matchmaker until you have a fully authenticated user to show it for. Until the playerAuthenticated event fires you cannot call any methods that require an authenticated user.
     
  6. Les-Bird

    Les-Bird

    Joined:
    Apr 22, 2013
    Posts:
    12
    @Prime[31], could it be possible that Unity 4.2.1's social API GameCenter stuff is conflicting with Prime[31] Game Center plugin? Just to recap, I can subscribe to playerAuthenticated like this:

    GameCenterManager.playerAuthenticated += playerAuthenticated;

    But it never gets called because "playerDidAuthenticate" never gets called and I can not subscribe to "playerDidAuthenticate".

    - Les
     
  7. Les-Bird

    Les-Bird

    Joined:
    Apr 22, 2013
    Posts:
    12
    @Prime[31] replied to my question on the Prime[31] support forum and it clued me in to what the real problem was. I was originally trying to get Unity's social API Game Center system to work but was not getting reliable results. During this time I had created an object in my scene called "GameCenterManager" which held all the data about our Game Center leaderboards including the leaderboard ID's, etc. When we decided to purchase the Prime[31] GameCenter plugin it would not work even though I was properly subscribing to the events as shown in the demo scripts. When Prime[31] replied that the log message "SendMessage: object GameCenterManager does not have receiver for function playerDidAuthenticate!" indicated that their GameCenterManager was not in the scene because I was not subscribing to any of it's events (which I was), I realized that my version of GameCenterManager was conflicting with the one Prime[31] has. They use a prefab-less system so I did not realize their plugin was trying to add it's own version of GameCenterManager into my scene. The solution was to just remove mine and create a new object called GameCenterListener.

    - Les
     
  8. DanarKayfi

    DanarKayfi

    Joined:
    Aug 27, 2012
    Posts:
    72
    Hi @Prime31,
    i want to buy the plugin but i have one question
    other than posting and showing results of the achievements and leader board

    is there a away by using gamecenter plug in to know the user friends scores?
    for example you the player reach a score greater than his gamecenter friend score, will show him a message that he get a higher score than his friend ?
     
  9. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @danar, to do that you need a server. The plugin lets you fetch a users friends and fetch scores for any user but it's up to you to determine when a players score is better than some other player.
     
  10. DanarKayfi

    DanarKayfi

    Joined:
    Aug 27, 2012
    Posts:
    72
    Awesome Thanks :)
     
  11. vbbartlett

    vbbartlett

    Joined:
    Dec 4, 2012
    Posts:
    25
    @prime31 - Im getting some odd behavior with the google play achievements. I report the achievement, wait for callback success and then call the getAllAchievementMetadata, problem is that it doesn't look like the getAllAchievementMetadata is updating the metadata for the achievements. The rewarded achievement still shows that it can be awarded.

    I can attempt to award it several times with the same result. So it isn't a timing thing. If I restart the app, it does update it so I think it is not actually getting the achievement, but rather getting a cached copy. Might this be the case?
     
  12. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @vbbartlett, that is an odd one. It sounds like Google is using state data. I'll add a method in to the next update to flush it out.
     
  13. vbbartlett

    vbbartlett

    Joined:
    Dec 4, 2012
    Posts:
    25
    @prime31, thanks. What is the eta on that? I am submitting to google in the next weekish...
    Just ran into another... problem, the bool returned to unlockAchievementSucceededEvent, returns false, but I have just unlocked it.
    I was trying to add code to account for the state not being correct.
     
  14. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @vbbartlett, the ETA is the same as all of our ETAs: when the code is written and tested on all supported devices and OS versions. The unlockAchievementSucceededEvent returns a bool for if the achievement is newlyUnlocked (never been unlocked before). If you are certain that you have never unlocked that achievement before you need to open a bug report with Google. The plugin merely returns the bool that Google sends to it.
     
  15. vbbartlett

    vbbartlett

    Joined:
    Dec 4, 2012
    Posts:
    25
    @prime31, ok. Some additional info for you, logging in and out with different accounts also does not clear the "cached" achievements.
     
  16. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @vbbartlett, that is something best sent to Google. Their SDK is closed source so we can't see or change any of their code.
     
  17. vbbartlett

    vbbartlett

    Joined:
    Dec 4, 2012
    Posts:
    25
    @prime31, isn't this best sent by prime31? I went to log it but I have no idea what is wrong. All I know is that your api isn't returning the correct information and values...
     
  18. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @vbbartlett, it is best sent by any and all developers who experience the issue. The more reports they get the better chance of getting a fast fix.
     
  19. vbbartlett

    vbbartlett

    Joined:
    Dec 4, 2012
    Posts:
    25
    @prime31 - seems like this has been updated. I would like to thank you guys. There is one bug with the process OR a callback that I didn't see documented.
    I am calling
    PlayGameServices.reloadAchievementAndLeaderboardData();
    achievements_And = PlayGameServices.getAllAchievementMetadata().ToArray();

    reload seems to actually take some amount of time to finish because the results are the same, but a second call shows the correct results.
    so... it sort of works...
     
  20. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @vbartlet, any meta data reloading will fire the reloadDataForKeySucceededEvent for each successful load.
     
  21. vbbartlett

    vbbartlett

    Joined:
    Dec 4, 2012
    Posts:
    25
    ah, ok. Thanks!
    One additional thing, looking at the docs for google play they have a reset which I have been unable to find exposed in this plugin. Is it planned? According to other searches, you can remove the user but that takes up to hours for that to filter out and get reset. It would be nice for testing purposes if like the iOS, you could clear the achievements.
     
  22. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @vbbartlett, they have no public API for the reset. It is only available using their raw REST API which the plugin does not use.
     
  23. nachobeard

    nachobeard

    Joined:
    May 7, 2013
    Posts:
    47
    Hello

    I am having an issue using the Game Center plugin.
    Several players are complaining that the score that gets submitted to Game Center disappears from the leaderboards after a while...

    "my highscores still keep disappearing from the GameCenter leaderboards. I just did a 144 second run and was registered for a few minutes. Now it's already gone again."

    this is quite a problem since my game is totally score-based (survive for as long as you can), and players with high scores look forward to being on the top of the list only to see their score disappear.

    are there any issues you could think of that could be happening?
    note this is happening in the live app which is currently on the appstore with real users.

    this is my code, which gets called every time the game ends:

    Code (csharp):
    1.  
    2. //overwrite best time
    3. float survivedTime = Time.time - startGameTime;
    4. int hundredths = (int)((survivedTime - Mathf.Floor(survivedTime))*100.0f);
    5. int seconds = Mathf.FloorToInt(survivedTime);          
    6. if (survivedTime > PlayerPrefs.GetFloat("bestSurvivedFor"))
    7. {
    8.     PlayerPrefs.SetFloat("bestSurvivedFor", survivedTime);
    9.    
    10.     //report score to game center
    11.     int score = seconds*100 + hundredths;
    12.     Debug.Log ("reporting game center score: " + score);
    13. #if UNITY_IPHONE
    14.     GameCenterBinding.reportScore(score, "LongestSurvivor");
    15. #endif
    16. }
    Any idea of what could be causing the problems?
    I'm freaking out a little bit :/

    Thanks
    -Nacho
     
    Last edited: Oct 9, 2013
  24. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @nacho, if scores are disappearing you need to get a bug report open with Apple. That would indicate there is an issue on their servers. You can't delete a score via their API.
     
  25. nachobeard

    nachobeard

    Joined:
    May 7, 2013
    Posts:
    47
    sure I mean, I'll do that but, why would it only happen to my game?
    it's kinda weird.
    thanks
    nacho
     
  26. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    266
    Heya Prime, had a question about Game Center login flow. I'm getting some odd behavior, just wondering if you have any insight.

    I call "authenticateLocalPlayer" on app startup, which works fine. The user can log in at that time and all works well.

    If the user cancels that login dialog, I give an opportunity later on for the user to login to Game Center. However, if I call "authenticateLocalPlayer" at that time, I receive the following series of events:
    1. authenticateWithCompletionHandler: enter
    2. authenticateWithCompletionHandler: exit
    3. GKPlayerAuthenticationDidChangeNotification fired
    4. GKPlayerAuthenticationDidChangeNotification fired
    5. "playerLoggedOut" event is fired
    6. "playerFailedToAuthenticate" event is fired with error "The requested operation could not be completed because local player has not been authenticated."
    or, sometimes:
    1. authenticateWithCompletionHandler: enter
    2. "playerFailedToAuthenticate" event is fired with error "The requested operation could not be completed because local player is already authenticating."

    When I've implemented this plugin in the past, I seem to recall subsequent calls to "authenticateLocalPlayer" working fine and showing the login dialog, until the player tries three times in a row and GC is disabled. The error messages returned kind of sound like GC is getting into an odd state at some point - the "FailedToAuthenticate" event giving the error "not authenticated" seems bizarre, for example. I don't need to be authenticated to authenticate???

    As always, any help or insights would be greatly appreciated. The login call always works correctly the first time the app is launched (until you reach that "Three Times in a Row" limit), but subsequent calls are acting weird.
     
  27. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @kromenak, once a player cancels if I am not mistaken Apple's docs say to remove all GameCenter UI from your game. GameCenter doesn't do well whenever you call authenticateLocalPlayer more than once per launch.
     
  28. Vaklav

    Vaklav

    Joined:
    Sep 27, 2012
    Posts:
    6
    Hello Prime.

    I'm having issues with my game achievements. Banners are not popping up correctly on ios7. When i build to ios6, everything works out fine, however, on ios7, most banners will simply not pop up, and when they do, they will do it twice in a row. Do you have any idea on why this would happen? I've double checked my code, and I do call showcompletionbannersForAchievements() right after the player is authenticated to gamecenter.
     
  29. vbbartlett

    vbbartlett

    Joined:
    Dec 4, 2012
    Posts:
    25
    @Vaklav
    I assume you are doing this in the sandbox? I have not tested with the 7.0.3 version but prior to that the sandbox did not pop those up correctly. HOWEVER we released a build a week ago and on the live server it displays those achievements correctly.
     
  30. Vaklav

    Vaklav

    Joined:
    Sep 27, 2012
    Posts:
    6
    You're correct Vbbartlett, I'm testing in a sandbox environment. Thanks for your response.
     
  31. laserlars

    laserlars

    Joined:
    Nov 17, 2011
    Posts:
    255
    Hi,
    I`m using the turn based plugin. When a game ends, and the app is in the background; handleMatchEndedEvent will NOT fire unless you enter the app from the game center notification.
    Any solutions for a workaround ? I´m keeping track of the amount of turn based games won by each player, and this really mess things up.

    Thanks!
     
  32. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @laserlars, it is normal for the event to not fire unless the notification is launched. That is just how Apple does things. You can still load all matches with loadMatches and retrieve the match data to see what happened in the match. That is the only persistent data available for any match.
     
  33. laserlars

    laserlars

    Joined:
    Nov 17, 2011
    Posts:
    255
    Ok, thanks for your quick reply.
    Kinda hard to keep track of which match is already counted for and not. If a user wins 15 matches, and uninstall/install the game he will gain 15 more points in the leaderboard :( but thanks.
     
  34. StevenSauer

    StevenSauer

    Joined:
    Mar 25, 2013
    Posts:
    19
    Hey Prime, recently I had to re-import your Game Center plugin as well as download Xcode. I got the newest versions of both and now I'm constantly getting this in my XCode builds (one of which is likely not your plugin, but just in case it could be interfering, I added it):

    Undefined symbols for architecture armv7:
    "_OBJC_CLASS_$_CTTelephonyNetworkInfo", referenced from:
    objc-class-ref in AmazonInsightsSDK.a(AIIOSDeviceDetails.o)
    "__gameCenterIsGameCenterAvailable", referenced from:
    RegisterMonoModules() in RegisterMonoModules.o

    Thanks in advanced.
     
  35. Dhia-eldeen

    Dhia-eldeen

    Joined:
    Jul 18, 2012
    Posts:
    14
    Hello, in turn based, how to get players aliases and how to get their game center profile photo ?
    PS : I know how to get friend photo, and local player alias, but what i need is
    - the opponent alias and game center photo.
    - the local player game center photo.

    Thanks.

    _________ EDIT _________

    i tried

    Code (csharp):
    1. GameCenterBinding.loadPlayerData(new string[] { ourPlayerId,nextPlayerId },true,false);
    but i don't know what to do next with, how to get the texture2D out of it ?

    Code (csharp):
    1.  
    2. void profilePhotoLoaded( string path )
    3. {
    4.          Debug.Log( "profilePhotoLoaded: " + path );   
    5. }
    6.  
    _________ EDIT _________

    after reading some of your posts, i made this, but the icon loads as a black image

    Code (csharp):
    1.  
    2. void profilePhotoLoaded( string path )
    3. {
    4.     Debug.Log( "############# profilePhotoLoaded: " + path );
    5.     var bytes = File.ReadAllBytes (path);
    6.     var tex = new Texture2D (128,128);
    7.     GameObject.Find ("Cube").renderer.material.mainTexture = tex;
    8. }
    9.  
    and this

    Code (csharp):
    1.  
    2. foreach( var p in _currentMatch.participants )
    3. {
    4.     if( p.playerId != ourPlayerId )
    5.     {
    6.         nextPlayerId = p.playerId;
    7.         GameCenterBinding.loadPlayerData(new string[] {nextPlayerId},true,false);
    8.         break;
    9.                    
    10.     }
    11. }
    12.  
     
    Last edited: Jan 19, 2014
  36. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @dhia, you loaded the image data into the bytes variable but your forgot to then use it. Texture2D has a LoadImageethod that you should call and then apply that by calling Apply.
     
  37. Dhia-eldeen

    Dhia-eldeen

    Joined:
    Jul 18, 2012
    Posts:
    14
    it shows a pink sandbox icon thing, i wonder what will show up after release... thanks for the advice

    the main question is:

    how to get the alias of the player i'm playing with (i know i can get it's ID using p.playerId , but i want the alias), i read in your posts that i have to use loadPlayerData
    do you mean this ?

    and then you mentioned that we have to use playerDataLoaded, but what i find odd that this function only shows the aliases of friends

    it worked with me and showed friends alias, but i need the alias of the opponent,

    the goal is to display the local player profile image and name, and the 2nd player name and profile image, to make a welcoming versus screen.

    do i have to change the +=/-= stuff for events listeners? i didn't touch these..

    Thanks a lot.
     
    Last edited: Jan 20, 2014
  38. laserlars

    laserlars

    Joined:
    Nov 17, 2011
    Posts:
    255
    It's all in playerDataLoaded;
    Just check what playerID is being returned. If it's not your own, then .... :)
     
  39. Dhia-eldeen

    Dhia-eldeen

    Joined:
    Jul 18, 2012
    Posts:
    14
    Code (csharp):
    1.  
    2. void playerDataLoaded( List<GameCenterPlayer> players )
    3. {
    4.     Debug.Log( "playerDataLoaded" );
    5.     foreach( GameCenterPlayer p in players )
    6.     {
    7.         Debug.Log("@@@@@@@@@ "+ p.alias );
    8.     }
    9. }
    10.  
    this only prints the name of friends, it doesn't print the name of the opponent, and when i remove the friend from game center, it doesn't even get fired.

    so it doesn't print my name to have it excluded or checked with if statement, etc...
     
  40. Dhia-eldeen

    Dhia-eldeen

    Joined:
    Jul 18, 2012
    Posts:
    14
    laserlars, did you try it ?

    prime31 : could you kindly provide some snippet to get the opponents aliases or display names.

    for the opponent photo, the cube still shows up as white, while when i try to get a friend photo, it gives a pink sandbox photo.

    the most important thing for now is the opponent alias

    aren't there any tic-tac-toe example using game center turn based ? ? ? if there is an example that works, and displays opponent photo/alias and local player photo/alias, then i would buy that if it has a moderate price.

    by the way, game center sandbox is buggy, sometimes the turn gets to the next player in 2 seconds, another times in 30 minutes.

    Thanks.
     
    Last edited: Jan 20, 2014
  41. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @dhia, that is the expected result. Apple provides that sandbox profile image when using the sandbox. @laserlars is correct. You load data from the playerId with Game Center via the loadPlayerData method.
     
  42. sliterod

    sliterod

    Joined:
    Jan 22, 2014
    Posts:
    2
    Hello! I'm trying to create a match programmatically after inviting friends. I want to know if there's is a way to never pass through Game Center UI for doing this.
    The other question I have is about the listeners. Which of the ones mentioned in your documentation is the right one for auto-matchs and for inviting friends. Thanks in advance.
     
  43. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @sliterod, invites require the Game Center UI to process. The best way to learn when the different events fire is to just open the demo scene on a device and play around with it. Every single event will be logged with it's name and the data it provides.
     
  44. sliterod

    sliterod

    Joined:
    Jan 22, 2014
    Posts:
    2
    Thanks! I'll check the demo.
     
  45. NickSergeev

    NickSergeev

    Joined:
    Dec 19, 2012
    Posts:
    15
    2prime31:

    hi guys, we're considering to buy this plugin but not sure about iOS7 - does it work fine with it?
    We need to be able to deal with achievements only.
    Thanks.
     
  46. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @nick, the plugin works fine with iOS 7
     
  47. Hesham

    Hesham

    Joined:
    May 29, 2008
    Posts:
    147
    The plugin was working fine since I installed it about a month ago, but today I noticed that none of the gamecenter function are working. Specifically the localplayer is never authenticated, hence nothing else is working.

    This is the output I get :

    Code (csharp):
    1. 2014-02-05 03:06:30.740[20768:60b] using iOS 6+ authentication handler
    2. 2014-02-05 03:06:31.453 [20768:60b] GKPlayerAuthenticationDidChangeNotification fired

    Really stomped here. Using a sandbox account and have (always had) gamecenter setup for development.
     
  48. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @hesham, every time the GKPlayerAuthenticationDidChangeNotification fired log occurs either the playerAuthenticated or playerLoggedOut event will fire. Ensure you properly setup your event handlers.
     
  49. Hesham

    Hesham

    Joined:
    May 29, 2008
    Posts:
    147
    Still the I cannot get the player to authenticate, here is my exact code:

    Code (csharp):
    1.  
    2. void Start () {
    3.         GameCenterManager.playerAuthenticated += playerAuth;
    4.         GameCenterManager.playerFailedToAuthenticate += failedtoauth;
    5.         GameCenterManager.playerLoggedOut += playerloggedout;
    6.         GameCenterBinding.authenticateLocalPlayer();
    7.  
    8.         StartCoroutine("nextScene");
    9.     }
    10.    
    11.     // Update is called once per frame
    12.     void Update () {
    13.    
    14.     }
    15.  
    16.  
    17.     void playerloggedout() {
    18.  
    19.         print ("player logged out event");
    20.     }
    21.  
    22.     void playerAuth ()
    23.     {
    24.         print ("auth success");
    25.     }
    26.  
    27.     void failedtoauth (string obj)
    28.     {
    29.         print ("failed to auth");
    30.     }
    31.  

    and this is the output I get :


    Code (csharp):
    1.  
    2. GKPlayerAuthenticationDidChangeNotification fired
    3. player logged out event
    4.  
    5. (Filename: /Applications/buildAgent/work/d3d49558e4d408f4/artifacts/iPhonePlayer-armv7Generated/UnityEngineDebug.cpp Line: 53)
    6.  
    7. failed to auth
    8.  
     
  50. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @hesham, I can't tell you why authentication fails. I can tell you the plugin is working fine. The event is firing and your log is being written. I would suggest first of all printing out the error message that the plugin sends to the playerFailedToAuthenticate event. If that doesn't provide a clue go back to the basics: double and triple check your iTunes Connect setup, test user setup, bundle ID, provisioning profile, etc.