Game Center Support

Discussion in 'iOS Development' started by DigitalDuane, Dec 26, 2011.

  1. DigitalDuane

    DigitalDuane

    New Member

    Joined:
    Dec 13, 2006
    Messages:
    39
    Seems like a lot of exciting developments and features with 3.5 and the Developer Preview. Has anybody figured out
    how to access the Game Center? Can some one provide some directions or tuts on connecting through the social networking API? Kinda like getting the keys to a brand new car for Christmas. But where the heck is the car? Not in garage! Not in driveway! It is a Beta release but we need a little more details to be all that we can be.

    DD
  2. luisanton

    luisanton

    Member

    Joined:
    Aug 25, 2009
    Messages:
    294
    I would also love knowing something about this. I was about to update our previous title with GameCenter using Prime31's plugin when I read somewhere that Unity3.5 will include Game Center! Is that true?

    If so, I guess it will be included and explained for Unity3.5 iOS, which has not been released yet... But when will it be released? If it is taking months I'll get Prime31's plugin : )
  3. BrUnO XaVIeR

    BrUnO XaVIeR

    Member

    Joined:
    Dec 6, 2010
    Messages:
    1,536
    Prime31's is still far better solution.
  4. freyr

    freyr

    New Member

    Joined:
    Apr 7, 2005
    Messages:
    1,148
    For initial documentation look up Documentation/Components/net-SocialAPI.html and Documentation/ScriptReference/Social.html in the Unity install folder on your machine. It defaults to using GameCenter on iOS and a dummy implementation in the editor.

    Foe now we only support GameCenter, buy you can extend it with your own implementation (ie, for Kongregate, OpenFeint, etc.). To do that, you can implement the ISocial interface, assign an instance of your custom class to Social.Active and keep the same code for every social platform you use. And remember to publish your implementation on the Asset Store ;-)
  5. luisanton

    luisanton

    Member

    Joined:
    Aug 25, 2009
    Messages:
    294
    Why, BrUnO? If GameCenter is supported by Unity 'natively' I prefer, by far, not having to pay for external plugins. The only reason why I would chose Prime31 in favor of Unity would be that Prime31 may be more flexible and able to update faster to changes in GameCenter... That's a pretty solid reason. What's yours?
  6. Dreamora

    Dreamora

    Member

    Joined:
    Apr 5, 2008
    Messages:
    26,586
    That Primes31 plugin does more than only highscores and a handfull of other things cause thats what the Social API is and to which all 'more capable' systems like GC will be forced to degenerate? :)
  7. luisanton

    luisanton

    Member

    Joined:
    Aug 25, 2009
    Messages:
    294
    Sorry, dreamora, I don't understand you :(
  8. Dreamora

    Dreamora

    Member

    Joined:
    Apr 5, 2008
    Messages:
    26,586
    Means that the Social API is written to be for social APIs, not explicitely for Game Center and all its features. As such there will be Game Center features it simply will never offer while Prime31 does it (thats one of the reasons apple wanted to ban Unity, Flash and many other techs in 2010, to never have technologies that don't support the full iOS potential in favor of supporting multiple platforms), cause the majority of social APIs lack it.
    voice chat, turn based multiplayer and alike to just name 2 things

    That being said I'm sure that Prime will rework his plugins in the future to comply to the Social API so you can use the social API commands for the 'base stuff' and still use the plugin own stuff for more sophisticated and complete things (cause there is nothing that prevents that from happening beside the fact that he might not want to complicate the usage by requiring you to use 2 distinct systems basically when you interact with the plugin directly + the social api)
  9. luisanton

    luisanton

    Member

    Joined:
    Aug 25, 2009
    Messages:
    294
    Ok, I agree. But sometimes you just need the most basic feature: highscore tables. And that's when an integrated Social API becomes handy, instead of a bigger gun like Prime31's plugin.

    Anyway, 3.5 is not fully available yet, so if I want to update our game these holidays with GameCenter I'll have to use the plugin. It used OpenFeint previously, but for some reason its last version does not work properly with Unity 3.4 and XCode 4 (game crashes).
  10. DigitalDuane

    DigitalDuane

    New Member

    Joined:
    Dec 13, 2006
    Messages:
    39
    @freyr Thanks for pointing me in the right direction. Unity is an incredible multi-dimensional tool. I'm still learning the basics in some areas. How to implement basic Game Center will do for the moment. I'll grow from there.
  11. figbash

    figbash

    Member

    Joined:
    May 13, 2008
    Messages:
    37
    I am confused as well, looking at the docs I don't see any way to bring up the game center dashboards (for leaderboards/achievements/etc). Is this not possible, and will it be?
  12. _Daniel_

    _Daniel_

    Member

    Joined:
    Feb 28, 2007
    Messages:
    1,737
    @figbash: Earlier they'd said it would come in a later beta (this was around b2 or 3). Unfortunately it appears it hasn't come yet; I really hope they release it in 3.5 and don't wait till a later version.

    @freyr: Wow, that sounds really cool how we can implement the ISocial interface in any way we wish. Very smart.
    Last edited: Jan 5, 2012
  13. gangrel

    gangrel

    New Member

    Joined:
    Jan 3, 2012
    Messages:
    28
    I've been doing some testing with this, and can successfully authenticate Game Center upon launching a test app, but then things go horribly wrong.

    During authentication, I'm getting an exception and the following message...

    Failed to download image: The requested operation could not be completed due to an error communicating with the server.
    The user probably does not have a profile photo set up

    Upon setting a profile pic and trying again, I got another exception in UnityEngine.GameCenter.PopulateLocalUser. Unfortunately, there was little information attached to the exception, so I haven't a clue what's going on and am still looking into it.

    Looks like there are still issues to be worked out. For example, it's perfectly valid for a player to not set a profile pic. Unity shouldn't fail there.
  14. gateway69

    gateway69

    Member

    Joined:
    Feb 18, 2010
    Messages:
    93
    anyone know if you invite a game center friend to play your app, if you can detect if they launched it and started playing?
  15. maynull

    maynull

    Member

    Joined:
    Oct 26, 2011
    Messages:
    26
    Anyone managed to figure out how to use GameCenter ?? I tried the script given in documentation and it didn't worked :/
  16. gangrel

    gangrel

    New Member

    Joined:
    Jan 3, 2012
    Messages:
    28
    @maynull The doc says Social.Authenticate, but you'll actually want to use Social.Default.Authenticate. The API doc seems to be out of date, so I've been relying upon the Assembly Browser in MonoDevelop. But as I mentioned above, I'm then getting exceptions before Authenticate returns, and am not sure what's going on.
  17. figbash

    figbash

    Member

    Joined:
    May 13, 2008
    Messages:
    37
    @gangrel: I'm getting the same crash, I wonder what the trick is to authenticating a profile.
  18. _Daniel_

    _Daniel_

    Member

    Joined:
    Feb 28, 2007
    Messages:
    1,737
    Found the commands to show ui. It's:

    Social.ShowAchievementsUI ();
    Social.ShowLeaderboardUI ();

    I tried the achievement one and it actually works :).
  19. figbash

    figbash

    Member

    Joined:
    May 13, 2008
    Messages:
    37
    gangrel: If you're still crashing out, it seems like ours works fine as long as we aren't attached to the debugger through the docking cable.
  20. gangrel

    gangrel

    New Member

    Joined:
    Jan 3, 2012
    Messages:
    28
    I didn't follow up on my prior issue, but whatever it was seems to have stopped -- even when docked. I have no idea why. #mystery

    On the other hand, while I am now successfully authenticating, and can view test achievement data, I'm not getting my test leaderboard data or friends. Though I guess this could just as easily be an issue with Game Center, as with Unity.
    Last edited: Jan 10, 2012
  21. DigitalDuane

    DigitalDuane

    New Member

    Joined:
    Dec 13, 2006
    Messages:
    39
    What an interesting thread! Well after 2 weeks I've come back. Thanks to gangrel's suggestion of using 'Social.Default.Authenticate' I'm clear of errors. But when I run the program I get a blank scene with the message: Error: no achievements found UnityEngine.Debug:Log(Object) .

    Can someone Please post an example of how they got the GC to work. Basically I just created an empty game object and dropped the corrected API script on there. But obviously it's not linking to anything.

    @Daniel, where did you place; Social.ShowAchievementsUI and (); Social.ShowLeaderboardUI (); ? Within the Social API script? Also how does one set up Achievements for the query to find? I'm sure others besides maynull and I are dying to know how to do a basic setup for this GameCenter API. I have a 'Shooting Gallery' type game. You shoot and hit as many targets as possible before time runs out. I have a scoring script integrated and working. It displays points scored in a GUI texture. In my little brain somehow I need to reference these two. Help!!!!!

    There are also in my Social Files folder a jquery.js file , a docs.css file and some png files. where do these come into play! Sorry to be so dense but I suppose this is the forum to ask questions!
    Last edited: Jan 14, 2012
  22. DigitalDuane

    DigitalDuane

    New Member

    Joined:
    Dec 13, 2006
    Messages:
    39
    Oooook! I added a little Pixie Dust to my cinnamon oatmeal this morn, and BAM! Game Center pops up on the development build on my iPad! Now I get a a Game Center box message asking me to sign in. After signing in, I get an error message saying 'This game is not recognized by Game Center. I imagine this is because I haven't enabled Game Center in iTunes Connect yet. Excuse me a moment while I 'Tebow' So, here's the drill @maynull and others who never attempt this amazing feat at home.

    > Create a new Javascript in Unity. I named it Game Center
    > Copy and Paste the Social API code into your new Game Center script.
    > Edit your code; changing 'Social.Authenticate', to 'Social.Default.Authenticate' as Gangrel suggested
    > In a new scene, or an appropriate scene, create an empty game object and add the script 'Game Center'.
    (I added 'Game Center' script to my existing Total Points scene.
    > Go into Xcode and add the Game Kit framework to your project. ****Very Important Step****** or the missing link
    >Go to you Project in Xcode >Click on Target > Build Phases > Click on the '+' sign and add the Game Kit.
    > *on the far right side of this line I changed 'optional' to 'required' Don't know if that's mandatory or not.
    >Connect your iPad or iPhone
    > Back in Unity 3.5, Hit build and run! Game Center sign in box should appear.

    If you don't know! Now you Know. :cool: Brother!
  23. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Messages:
    10,312
    Think I'll be sticking with prime's expensive-but-working* solution for the time being!



    * 200 dollars worth if you get the whole lot. Thats half of ios basic so yeah, expensive... but good.
  24. bug5532

    bug5532

    Member

    Joined:
    Aug 16, 2011
    Messages:
    250
    Hi, I got Game Center login to work, but once its logged in my game just freezes with the "User has successfully logged in" message. Did anyone get any further than this?
    I'm getting a Bad Access error in UnityEngine_GameCenter_PopulateLocalUser:
    Any Ideas?
  25. NicholasFrancis

    NicholasFrancis

    Member

    Joined:
    Apr 8, 2005
    Messages:
    1,587
    Please submit a bug report including the project - then we'll try to see if it's something on our end.

    (and please PM me the case number)
  26. bug5532

    bug5532

    Member

    Joined:
    Aug 16, 2011
    Messages:
    250
    PM'ed, was reproducible with just the script though:
    Code (csharp):
    1. function Start () {
    2.  print("Logging into GC");
    3.     Social.Default.Authenticate( ProcessAuthentication );
    4.  print("Crash?");
    5. }
    6.  
    7. static function ProcessAuthentication( success: boolean)
    8. {
    9.     if (success)
    10.     {
    11.         Debug.Log("Authenticated");
    12.  
    13.         // Do what when logged in?
    14.     }
    15.     else
    16.         Debug.Log("Failed to authenticate");
    17. }
    It freezes up just after login, with "Welcome back, User /n *** Sandbox ***" notification on screen.
    ProcessAuthentication is never called.

    Thanks for any help :)
    Last edited: Jan 18, 2012
  27. gangrel

    gangrel

    New Member

    Joined:
    Jan 3, 2012
    Messages:
    28
    @nicholas and @Bug5532...

    What Bug is seeing is similar to what I was seeing at first, in that I was getting an exception on authentication because my account didn't have a profile pic attached to it. Once I added a profile pic, the exception went away.

    Bug, are you seeing a comment in the log about the account not having a profile pic?

    It's unreasonable to assume that the player will have a profile pic. When the library confirms authentication, it should test for the existence of a profile pic, and if there's one present can perhaps load it, but shouldn't except on it (instead providing a placeholder pic, in absence of one on Game Canter).

    I'm also experiencing another issue, after authentication. Upon hitting my authentication callback, I call Social.localUser.loadFriends(). But, I hit another exception there. I don't know what the issue is, obviously, since I can't see code, but something's failing when retrieving the friend list from Game Center. Perhaps it's also failing on the friend accounts not having profile pictures? I could verify by setting pics on them, and seeing if it succeeds, but I haven't tested that yet.
    Last edited: Jan 18, 2012
  28. bug5532

    bug5532

    Member

    Joined:
    Aug 16, 2011
    Messages:
    250
    hmmm yes I was receiving that message, but it made no difference to me when I added a profile picture. It still froze up at the same point :( .
  29. gangrel

    gangrel

    New Member

    Joined:
    Jan 3, 2012
    Messages:
    28
    Interesting.

    Another thing I noticed is that it takes Game Center some time to catch up. When I added a profile pic, it still didn't work at first. When I created and friended my test accounts, it took about 40 minutes before I could see the friend connections even within Game Center.

    Can you check your Game Center account, verify that you have a profile picture, and test again within your Unity App?
    Last edited: Jan 19, 2012
  30. bug5532

    bug5532

    Member

    Joined:
    Aug 16, 2011
    Messages:
    250
    I changed nothing and today it started working! odd but I'm not going to complain, thanks for your help!
  31. gangrel

    gangrel

    New Member

    Joined:
    Jan 3, 2012
    Messages:
    28
    Probably the Game Center delay I mentioned. Still, if Unity's assuming the presence of a profile pic, their code needs to change.

    Oddly, I now have a non-functional app. I separated out Social.Default.Authenticate and Social.localUser.LoadFriends into a separate app, so I could file a bug report on my LoadFriends issue, and am now failing on authenticate. #sigh
    Last edited: Jan 19, 2012
  32. bug5532

    bug5532

    Member

    Joined:
    Aug 16, 2011
    Messages:
    250
    Any idea on how to get a score to report properly? I report the score, it says it's been a success but then it doesn't appear in the leaderboards. Although it says that the has been 1 score in the leaderboard but then when you click on it theres no scores there :(

    Also when using Social.ShowLeaderboardUI () can you select a certain leaderboard to open on?
  33. gangrel

    gangrel

    New Member

    Joined:
    Jan 3, 2012
    Messages:
    28
    I've successfully reported achievements, but haven't yet seen scores appear in the leaderboard. I'm wondering if it doesn't show unless there are also scores by friends? I'm not sure, and haven't looked into it, yet. Right now I'm working on getting push notifications to work, while waiting for a bug response on my prior issue.
  34. bug5532

    bug5532

    Member

    Joined:
    Aug 16, 2011
    Messages:
    250
    Surely it should work with global highscores? Even so, I cant even see my submitted score... but weirdly it definitely looks like it has been submitted! ah why is this so difficult, haha
  35. bug5532

    bug5532

    Member

    Joined:
    Aug 16, 2011
    Messages:
    250
    So has anyone managed to get highscores to submit? If so, how?
  36. larus

    larus

    Unity Technologies

    Joined:
    Oct 12, 2007
    Messages:
    198
    We do not expect users to set up profile image and there is no exception. When loading profile images we print any error which might occur and it just so happens that GameCenter returns an error when no image is found. An empty placeholder image is used in this case.

    You should not be going through Social.Default, this could be the source of your troubles. This has been refactored away in the next preview release, try just using Social.* directly.
    We have not been able to reproduce authentication issues (with or without profile images on the local user), PM me the bug number if you have reported any and not received a response.

    Leaderboard should work, but when testing in the sandbox there are usually delays. I'm not sure how much delay you should expect but I've noticed scores popping up the day after I submitted.
  37. gangrel

    gangrel

    New Member

    Joined:
    Jan 3, 2012
    Messages:
    28
    @larus,

    I'm currently using the public b06, in which there is no Social.Authenticate -- hence my using Social.Default.Authenticate. When will there be a new beta?
    Last edited: Jan 20, 2012
  38. bug5532

    bug5532

    Member

    Joined:
    Aug 16, 2011
    Messages:
    250
    Strange, It's been over 24hrs since I submitted scores and still they haven't appeared. I will leave it a while longer, maybe there'll appear one day :)

    Edit: Success! Just logged out of game center and then in with another account and I can see the score! yay
    Last edited: Jan 21, 2012
  39. bug5532

    bug5532

    Member

    Joined:
    Aug 16, 2011
    Messages:
    250
    New question, Is there anyway to load up a specific leaderboard?
  40. larus

    larus

    Unity Technologies

    Joined:
    Oct 12, 2007
    Messages:
    198
    The leaderboard identifier is the first parameter in the Social.LoadScore() method, and is set in the Leaderboard.category property (in the next release this is renamed to simply Leaderboard.id).

    Try using Social.localUser.Authenticate(), I've replied to your bug report. The new developer preview release should be out soon, afaik.
  41. gangrel

    gangrel

    New Member

    Joined:
    Jan 3, 2012
    Messages:
    28
    I switched to Social.localUser.Authenticate, and am able to authenticate again. Oddly, Social.Default.Authenticate had been working fine. It just stopped working, though I was using the same version of Unity.

    The ongoing problem, beyond authentication, is that Social.localUser.LocalFriends never returns. I'm still getting a crash within Unity, after making the call. I'll file a new report on this.
  42. bug5532

    bug5532

    Member

    Joined:
    Aug 16, 2011
    Messages:
    250
    I want to load the Game Center leaderboards, not just the scores. At the moment I use Social.ShowLeaderboardUI(); but this only opens the first leaderboard (Default) and it wont take any variables.
    Any Ideas?
  43. quitebuttery

    quitebuttery

    Member

    Joined:
    Mar 12, 2011
    Messages:
    192
    Is there a way to automatically log in the user? I see most games just log in whoever is logged in via the Game Center app. Is there a way to do this via the Social API? Otherwise I got it working perfectly.
  44. larus

    larus

    Unity Technologies

    Joined:
    Oct 12, 2007
    Messages:
    198
    Yeah, it starts with the default leaderboard, then the UI has a button in the top left corner where you can view all the other leaderboards. At the moment we don't expose a way to jump to a specific one but it would be easy to add (maybe just as a gamecenter specific function with timescope as well as that's all they expose).

    This is how the Social.localUser.Authenticate() call should work. If you are already authenticated against GameCenter it should not trigger the login dialog and the callback just gets triggered with a success value. Please file a bug report if this isn't working as expected and send me a PM with the case number.
  45. bug5532

    bug5532

    Member

    Joined:
    Aug 16, 2011
    Messages:
    250
    Do you think this will be added soon?
  46. quitebuttery

    quitebuttery

    Member

    Joined:
    Mar 12, 2011
    Messages:
    192
    So apparently there's no way to clear an achievement? I don't see an API call for it--and you can't report progress with 0 if it's already completed.

    This is SUPER NECESSARY. Puhleeeze implement this.
  47. quitebuttery

    quitebuttery

    Member

    Joined:
    Mar 12, 2011
    Messages:
    192
    Oh wait, duh, I see it in GameCenter Platform. Weird, it doesn't come up in the autocomplete in MonoDevelop.
  48. quitebuttery

    quitebuttery

    Member

    Joined:
    Mar 12, 2011
    Messages:
    192
    Altough...GameCenterPlatform is not found in Unity 3.5 RC1. What's up with this class? How do you access it? Does it exist yet? It's in the documentation.
  49. gangrel

    gangrel

    New Member

    Joined:
    Jan 3, 2012
    Messages:
    28
    The documentation isn't necessarily up to date. I often find myself coding via auto-complete, or by bringing up the Assembly Browser in MonoDevelop, so I can browse the contents of a class.

    Also regarding my prior comment on Social.localUser.LoadFriends, friends are loading as of 3.5.0f1.
  50. quitebuttery

    quitebuttery

    Member

    Joined:
    Mar 12, 2011
    Messages:
    192
    What is the real proper way to use this object?

    If localUser is valid, we shouldn't try authenticating right? We can just use that localUser object? Does it pick up the localUser from who is logged in via the separate Game Center app?