Google Play Game Services for Unity

Google announced Google Game Play Services (GPG) for iOS and Android about 2 days ago at Google I/O. The most important part for us is the ability to save game progress in Google Cloud and realtime Multiplayer game support. This brings Google upto mark with iOS GameCenter.

We just created a plugin for Unity for iOS and Android for GPG with following features

  • Google Cloud Save
  • Leaderboards
  • Achievements
  • Signin/SilentSignin

Google Play Game Services Unity Plugin Demo

In coming weeks we shall add support for Android as well.

Multiplayer matchmaking will be a bit of work since state synch will have to be done from scratch just like it needs to be done for GameCenter. The Unity.Network would not be helpful in multiplayer without a Unity Raknet MasterServer.

The code is available as opensource at https://github.com/faizann/UnityGPGPlugin

Update June 16, 2013

The code now supports Android plugin as well.

105 Comments

  • Kledson Soares says:

    when the android version is coming out?

  • punchi says:

    Thanks for the free plugin guys!! ­čśÇ hope you release the Android version soon ^_^

  • Jose Rosario says:

    i really cant wait until mid june this is so interesting!!!!!!

    • FaizanN says:

      We need the plugin ourselves and I will upload android code on github by Monday. Multiplayer feature will have to wait for later date.

  • Jose Rosario says:

    yeah its almost monday, cant wait to see how your plugin works and looks, really excited

  • Jose Rosario says:

    i hope you can release this today, im really curious to see this in action

    • FaizanN says:

      Sorry for delay. It was a lot of work and I had some other work that kept me busy. The code is updated on github for Android.

  • Jojo says:

    No update yet?

    • FaizanN says:

      Almost done. The part to send rawbytes from MONO to JAVA is not elegant. I will do a hack today to get it done and upload code. Should be done in a few hours.

  • Meganubis says:

    was the plugin updated?

    • FaizanN says:

      Yes just updated. Android was a lot of pain to build that plugin.
      I also have iCloud plugin if someone is interested I can put it on github

  • Patricio Gonz├ílez Sevilla says:

    Thanks Faizan!

    Is this compatible with Unity 3.5.x?

  • MMR says:

    Hi, when you will be done with multiplayer feature. Also can you share eclipse project(the project having classes extended with unity player) as well?

    • FaizanN says:

      Hi
      Multiplayer feature we will do in a month or so.
      The extended classes are generated by Unity itself when you request it to generate eclipse project. The names are dependent on your project and I don’t think you need to change anything there.

      • MMR says:

        I have tried using your unity project as it is (just moving 2 files from editor to android folder). App crashed on pressing Init GPG button? Am I missing something.

      • MMR says:

        I have tried to test by making an apk from your code but on Init button app crashes. Kindly let me know if I am missing anything.

        • FaizanN says:

          I can’t say without checking the logs. Can you check what it says just before crashing and what is the reason?

          • MMR says:

            ayerNativeActivity (server)’
            I/Unity (29107): Init called
            I/Unity (29107):
            I/Unity (29107): (Filename: ./Runtime/ExportGenerated/AndroidManaged/UnityEngineDebug.cpp Line: 43)
            I/Unity (29107):
            I/Unity (29107): NerdGPG instance not found. Creating new one
            I/Unity (29107):
            I/Unity (29107): (Filename: ./Runtime/ExportGenerated/AndroidManaged/UnityEngineDebug.cpp Line: 43)
            I/Unity (29107):
            I/Unity (29107): Current activity UnityEngine.AndroidJavaObject
            I/Unity (29107):
            I/Unity (29107): (Filename: ./Runtime/ExportGenerated/AndroidManaged/UnityEngineDebug.cpp Line: 43)
            I/Unity (29107):
            E/Unity (29107): JNI: Unable to find constructor method id with signature ‘()V’
            E/Unity (29107):
            E/Unity (29107): (Filename: ./Runtime/ExportGenerated/AndroidManaged/UnityEngineDebug.cpp Line: 43)
            E/Unity (29107):
            E/Unity (29107): JNI: Unable to find field id for ‘mDebugLog’
            E/Unity (29107):
            E/Unity (29107): (Filename: ./Runtime/ExportGenerated/AndroidManaged/UnityEngineDebug.cpp Line: 43)
            E/Unity (29107):
            E/Unity (29107): JNI: Unable to find field id for ‘gameObjectName’ (static)
            E/Unity (29107):
            E/Unity (29107): (Filename: ./Runtime/ExportGenerated/AndroidManaged/UnityEngineDebug.cpp Line: 43)
            E/Unity (29107):
            I/DEBUG ( 2574): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

          • FaizanN says:

            Hi

            It looks like the java code is not compiled into your app. This way it is unable to find the class or methods on it. Check in intermediate files generated and your eclipse project.

            Check if this file is part of you Eclipse project https://github.com/faizann/UnityGPGPlugin/blob/master/Assets/Editor/googleplay_data/android_code/com/nerdiacs/nerdgpgplugin/NerdGPG.java

          • MMR says:

            Faizan it will be very kind of you if you share step by step integration of your plugin in any android app. Actually I am not getting the point how it has missed the file.

          • MMR says:

            NerdGPG.Instance().init(clientId,name);

            What to send in name???

          • FaizanN says:

            Did you look at the sample code?
            The name is inherited variable from MonoBehaviour and is name of gameObject to which script is attached.
            These are basic Unity concepts for scripting and here is the file from github that uses it.
            https://github.com/faizann/UnityGPGPlugin/blob/master/Assets/GPGGui.cs

          • MMR says:

            Faozan I have also posted queries regarding the steps. Also the said file is not appearing in my project.

          • nerdiacs says:

            Hi

            Why don’t you add the file yourself to project. Is this your own project or you tried the sample provided from Github?

          • MMR says:

            Initially github project.

            I have tried that but same issue

          • MMR says:

            Also I have tested in Unity Editor. It creates a game object NerdGPG with a script attached NerdGPG.cs. By this in a same scene I have two gameobjects having same script.

          • nerdiacs says:

            Hi Dude
            Now I see the issue.
            You cannot use an Android plugin in Unity Editor. You can only use it/test it on Android phone itself. On github it is mentioned that plugin only supports Android and iOS. No windows/macosx/linux.

          • MMR says:

            No man I am testing it on android device.

            I just checked it on editor.

          • MMR says:

            there???

          • nerdiacs says:

            I sent you message via email. Lets discuss an share project there to see what is wrong.

          • MMR says:

            I want to share my unity’s and eclipse screenshot. So, you can tell me better

          • MMR says:

            No its not a part of my project

          • MMR says:

            i have performed steps mentions at https://github.com/faizann/UnityGPGPlugin

  • Silveryard says:

    Hey,
    i do have a weird problem.
    When i install the sample scene on my android phone (all steps from github done) an i click on “init” then my app closes instantly

    • FaizanN says:

      You probably don’t have the library included or could be anything else.
      Better get logs and post an issue on github if you think this is really an issue with code.

    • I had this issue as well and what i did to get past it was to delete the plugin and reinstall it. then I changed my app ID to the correct number in the nerdGPG file and then hit the UpdateGPGFiles in Nerdiacs. This resolved the issue for me.

  • John says:

    Is this compatible with Unity 4.0?

    • FaizanN says:

      Yes completely. Unity 4.2 uses Android Studio and that means that PostBuildScript fails to automate the process and you have to do more work for configuring the project. It is documented in Readme on github.

  • parjanyaroy says:

    I am trying to integrate the plugin but facing an error in NerdGPG.cs on line numbers..47 , 69 , 123 , 213 saying “not all code paths return a value” … all four error messages are the same .please help me out

  • David Norman says:

    I greatly appreciate this plugin you’ve made and plan to make great use of it! However, I have a problem in that after I get the game to open up the sign in screen, and I hit accept for what the game wants access to, which sends me back into the game, nothing changes. Clicking to sign in again brings up the same window that requires accepting. Your troubleshooting does mention a sign in problem that may be the same (it’s very vague), but I can’t figure out how to fix it from what was written. Could you give a bit more detail, please?

    • FaizanN says:

      Hi
      In your Google console where you configured googleplay service check if your certificate’s sha has matches the one in the configs. debug.keystore stores your default key for android on your PC/Mac. This is most probably the issue.

      If not then get some logs and create an issue on github and we can discuss the solution.

      • David Norman says:

        Thank you for the response! However, I’m working with iOS, and I’m thinking that makes a difference.

        • FaizanN says:

          Hi
          If you are using Unity 4.2 the name of AppController.mm is changed to UnityAppController.mm and patch would have failed to add openUrl function in the file.
          Check if you have this method openUrl as per this patch file
          https://github.com/faizann/UnityGPGPlugin/blob/master/Assets/Editor/googleplay_data/gpg_appcontroller.patch

          • David Norman says:

            I am using Unity 4.2 and I do have that patch file, as downloaded with the rest of the package. Do I need to do something else with it?

          • nerdiacs says:

            Yes. you have to manually do the patch because file names have changed. You can google on how to do it or you can just read code from patch file mentioned and copy/paste it in right place in your UnityAppController.mm

          • David Norman says:

            Okay, I found UnityAppController.mm in the xcode project after building from Unity and fixed that according to the patch (at least I hope I did that correctly). There was only a slight change.

            To clarify the original problem, clicking SignIn in the game opened safari onto a “Do you want to allow this app toÔÇŽ” page with an accept and decline button at the bottom. Hitting accept took the player back to the app, but also reset the app, including the loading. Then, as the player is still not signed in, clicking SignIn again goes back to the same Accept page as before, with the problem repeating.

            After adding to the .mm code according to the patch, the only change is that the app does not reset when you are returned to it, with the music picking up where it left off as if it were paused.

            Although, as I write this, I wonder if I may be mistaken about there being a change at all, as I did not think to test thoroughly on the resetting of the app beforehand. If necessary, I can do so.

            Thank you very much for assisting me on this!

          • Francis R. Griffiths-Keam says:

            Did you find a solution to this problem? I’m having pretty much the same difficulties using Unity 4.3

          • Francis R. Griffiths-Keam says:

            Never mind. By removing the chrome conditional of the patch, I was able to successfully sign in via Safari. So I just replaced the contents of the openURL method in UnityAppController.mm with this: return [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation];

            EDIT2: Sorry about the mangled code below, this site’s string sanitiser doesn’t like angular brackets.

            EDIT: As well as adding “#import ” underneath “#include “

          • FaizanN says:

            You don’t need it anymore. The patch system moved to cs script and is now compatible with windows. Kindly check out the latest version and use that.

          • Guest364564 says:

            Thanks for quick reply.

  • David Norman says:

    Hello, again! After getting through the sign in problem, I found that I could not pull up achievements. It shows a window that it says is loading, but it never loads anything. I am thinking it has to do with the XCode log saying things like “Application ID expected to be a valid, non-empty string.” My app is not yet released, is that what it is referring to? Do I have to release my app on the app store to test achievements and such?

    Any help is appreciated!

    • FaizanN says:

      Hi

      You don’t have to release app but you do have to setup achievements etc on the google play console.
      At init you should be giving an applicationId which is called clientId in the code. You should check if it is correct one.
      You have use your test user that you added in console or else most things don’t work.

  • kebrus says:

    i think i’m missing a step or failing in some part… this is what i did:

    1. created a new eclipse android project and added both gps-lib and unity exported files into the project
    2. added the dependency like stated in the readme
    3. copied both unity-classes.jar and google-play-services.jar into Plugin/Android in Unity
    4. copied androidmanifest and added the missing lines like stated in the readme
    5. try to build and run on my phone and i get an error “CommandInvokationFailure: Unable to convert classes into dex format.”

    this is followed by a really long console error, what am i doing wrong?

    • kebrus says:

      thx for the update, i had a few problems because of the manifest file but now everything is working, thx a lot for this plugin

      • kebrus says:

        sorry for the spam but after further testing i was noticing data cloud was being loaded but not changing anything in the example provided, and the reasong is because NerdGPG doesn’t have access to GPGGUI and this happens because the instance function always creates a new object in the first run, so the callback functions being used are the ones found in NerdGPG and not GPGGui, i created a awake function that set the instance to itself and now the the script runs GPGGui callback functions and everything works ok

        thought this might be useful to someone

  • Dzxyan Hoh says:

    I had a problem with achievement,
    i don’t understand Social.ReportProgress(testAchievement, 100.0, OnUnlockAC);

    The 100.0 is mean for?

  • Alok says:

    Hi,

    Do I need to have the gpggui class in my asset before the build or can I remove it.

  • Roman Korchmenko says:

    Hi Faizan, I am a beginner and I can not understand, how to submit Achievements. need prior to this in “awake” or before ReportProgress do:
    Social.LoadAchievementDescriptions (OnLoadACDesc);
    Social.LoadAchievements (OnLoadAC);
    p/s/ sorry sorry for my english:)

    • FaizanN says:

      Hi

      Ideally you should load achievements once at start of scene so that you get all the information needed. Checkout the code included as an example.

      • Roman Korchmenko says:

        Thanks for the quick reply. I tried the example, but so unlock Achievement works every time (maybe this is the problem of Google)

        void FirstStrikeSubmitAchivement()
        {
        Social.ReportProgress(FirstStrikeAchievement, 100.0, OnUnlockAC);
        Debug.Log(“FirstStrikeAchievement”);
        }

        FirstStrikeSubmitAchivement call from SendMessage, Debug.Log work, all id`s setup correctly.
        “Ideally you should load achievements once at start of scene so that you get all the information needed”
        void Start () {
        Social.Active = new UnityEngine.SocialPlatforms.GPGSocial();
        Social.localUser.Authenticate(OnAuthCB);
        Social.LoadAchievements(OnLoadAC);
        Social.LoadAchievementDescriptions(OnLoadACDesc);
        }
        like this?

  • Dzxyan Hoh says:

    Suddenly i have a problem, may i retrieve my leaderboard score from google play games services to my phone, not the showing the leaderboard, i just wanna the score.

  • mars says:

    Hey,

    I am using the plugin for android, but in the test scene I always get “GPGGUI: Got Login Response: False” and when I click on the GPG_HasAuthoriser-button:”HasAuthoriser result False”, did I miss an option or something?
    I followed the instructions from https://github.com/faizann/UnityGPGPlugin.

  • ushadow says:

    Hello Faizan! I’m usign your plugin for doing some tests and I succeeded in uploading scores to leaderboards and to unlock single-step achievements but when I report a new progress for an incremental achievement I get a warning talling me “Calculated steps for achievement and known steps dont match! Calcualted steps: 1 Known: 0” followed by an IllegalStateException “Number of steps must be greater than 0”.
    My call is Social.ReportProgress(achievement.id, percent, success => { Debug.Log(success ? “ok” : “ko”); }); where I debugged both achievement.id and percent before the call and the ID is correct while the percent (double) was 10.0d for one achievement and 0.5d for the other one. You think you can help me a little? Thank you in advance!

    • FaizanN says:

      Hi
      Is the error in Java or C#?

      You have to setup stepping in google play web console for achievement. I guess there is mismatch as to how many it expects and you are providing.

  • Dzxyan Hoh says:

    I wanna ask a question, if i have many google account, how to make it auto select one account with asking permission in second time

  • Mart says:

    Hello,
    Im using plugin on android and it work great, but I have problems with iOS.
    It looks like callbacks in NerdGPG are not called. Could You help me figure this out?
    I think I done everything ok with project setup.
    When I tap sign-in button in example scene Safari opens, Im loggin in with my tester account credentials, accepting permission to use data by sample app. Then sample app goes back to foreground and nothing happens.
    I put debug prints in different parts of code – and it looks like callbacks are not called.
    I tried to force showing all leaderboards – UI showed up but I wasnt logged in in the app – so it was empty, nothing loaded.

    • nerdiacs says:

      Hi yeah there was issue with SetGameObject function in C# where it was not getting name of object. I have fixed that and pushed changes. Please update

  • M says:

    Hello. I can see in the code that some methods, like loadAchievements or incrementAchievement are not implemented for iOS. Is there a plan to implement them? And some of them are not valid for iOS – like getPlayerName – why it is not valid, what could I use?

    • FaizanN says:

      Hi
      Some of the APIs are just not available on iOs and some we haven’t implemented. Anyway, in next 4 weeks we’ll update code for more iOS support. Looks like so far people have been more interested in Android code. If you can add code on iOS side then do fork the project and send a pull request.

      Thanks

  • Horus developer says:

    Great Plugin thanks!

  • Pedram says:

    Hi, I have a problem using the plugin for android. When I call showAchievements() I get my achievements and there is no issue, but when I click back the game crashes. This does not happen if I have posted on facebook before I show my achievements.

    The error I get when I check my logcat is:

    channel ‘427c8298 com.bundleid/com.nerdiacs.nerdgpgplugin.NerdUnityPlayerActivity (server)’ ~ Consumer closed input channel or an error occurred. events=0x9

    E/InputDispatcher( 612): channel ‘427c8298 com.bundleid/com.nerdiacs.nerdgpgplugin.NerdUnityPlayerActivity (server)’ ~ Channel is unrecoverably broken and will be disposed!

    Attempted to unregister already unregistered input channel ‘427c8298 com.bundleid/com.nerdiacs.nerdgpgplugin.NerdUnityPlayerActivity (server)’

  • raj mehta says:

    Thanks for the plugin guys works great however i noticed that if i have more than one account in my android phone and i press sign in button it shows me a list of all the accounts i have and asks me to sign in by any one of the accounts.Choosing any account and pressing ok button directs me to the same window and this goes on and on and my game becomes unusable so plz help me as i absolutely love this plugin and don’t want to abandon it.

    • FaizanN says:

      strange. You should check logs in logcat. It could be that signin is not working with an account or it is not in added as developer user in google console.

      • raj mehta says:

        thanks for replying so quickly.first my phone was having account demo1@gmail.com i installed the demo gpg scene and it worked fine than i uninstalled the application and added another account demo2@gmail.com to my phone and again reinstalled the app to my phone and the issue started coming and now it is not accepting the first email that it was accepting first when there was only one account.and adding a testing account to developer console is only needed when we have not published our app i have already published my app and yesterday couple of users gave it one star because of this issue

        • FaizanN says:

          Yeah that is indeed a bug. Do you get anything in logcat as to what is going on? I dont have a published app to test myself.

  • So I followed the instructions as per the docs on GH but when I start my TEST app, I press the signin button and it takes me to the login page for google play and I accept. When i accept, it takes me back to the screen as if nothing has happened. In my production app, I have a string that is output “false” if the user is not authenticated. When I sign in here, it always comes back as false. I have read all the questions and answers below and the question by David Norman is the closest but I’m on an android device, not iOS. Any help on this one?

    • Solved*** I was using the Developer tools on my device as expected but I was NOT force quitting all of my settings when I would exit the app so it was holding old values that didn’t work at all. Go into your developer settings and change that if anyone else runs into this.

  • Krzysztof Pudlowski says:

    I can send my score
    Social.ReportScore(highScore,testLeaderBoard,OnSubmitScore);

    But this code doesn’t work, so I cannot get leaderboard.

    Social.LoadScores(testLeaderBoard,OnLoadScore);

    My platform : Android and Unity 4.3 (Windows 7 64-bit)

    According to logs nothing happens.

    —————
    public void OnLoadScore(IScore[] scores)
    {
    Debug.Log(“GPGUI: OnLoadScore:”);
    Debug.Log(“GPGUI: OnLoadScore: ” + scores.Length);

    if (scores.Length > 0) {
    //Debug.Log (“Got ” + scores.Length + ” scores”);
    string myScores = “Leaderboard:n”;
    int counter=0;
    foreach (IScore score in scores)
    {

    counter++;
    }
    Debug.Log (myScores);
    }

    }

    ——————

  • Guest says:

    I’m using it on Android

  • William Ma says:

    Hi,

    I am using the plugin with Unity version 4.3.0 on OSX, the plugin was working very well, I really appropriate your contribution. However, I have an issue when showing leader boards UI, when I pressed the “back” button on my device (Xperia Ion and Lenovo A390), the ANR (“Activity not responding”) popup is displayed, this is my screen sort of this issue http://screencast.com/t/BFOM2dUqaj8.

    After that, I used Logcat to see the error message. This is the result http://screencast.com/t/3cZLpn01

    Could you please to give me the instruction how to fix this issue?

    • FaizanN says:

      There are bugs due to new version and some existing ones found now. I am going to work things out and update this week.

  • Light says:

    Setup nerd gpg and everything worked perfectly. Installed Google adMob plug in and cannot build as long as nerd gpg is present. Anyone have this issue or know how to fix?

Leave a Reply