Integrate Google Play Services with Blueprint

Hello everyone

I’ve had a frustrating three weeks trying to figure this out given the default blueprints. With some help from Unreal Engine User Xunil who looked at the Unreal Engine source code (and a lot of fumbling in the dark) we figured out together how to make this work. Before you start reading this tutorial make sure you meet the following requirements:

  • Unreal Engine 4.9.2 or Newer (Confirmed working in 4.10)
  • Got a Google Developer Account (One time payment of 25 dollars)
  • Got an APK ready to upload or already uploaded to the Google Developer Console
  • Got a working Alpha/Beta/Production build on the Google App Store. (In this case mine is in Closed Alpha)

If you meet all of these requirements then read on!

Lets have a look at the Google Developer Console First. You need to set up a couple of things first before it’ll work at all. Otherwise you may run into your game crashing (like I experienced) or the service not working at all, with no error messages whatsoever.

In the console you should see something like this:


Now click the app in the console and go to In-App Products. If you don’t have any products in here and plan to have them, make one now for testing or those you already know you are going to have.

Moving on, go to the Services and API section. It should look something like this (I greyed out my RSA Public Key):

The key in that box should already be in your project settings of your Unreal Engine Project like so:

Now up to the left press the Game Services box. You should see something like this:


Pressing your Game Service here should bring up a slew of other options such as Achievements and Leaderboards. If you haven’t set these up yet, you can do so now. The Leaderboard and Achievements will have ID’s associated with them (like the In-app purchases) and you will need those later in the editor when we go to set that up so keep the information on hand until then.

Now we should be done with that part of the Console. Now go here: Google Cloud Platform
It should take you to your projects API Console. If it doesn’t then make sure you are logged in to the console in the browser you are currently using.

You need to go and Enable 7 different APIs to make this work. These are:

  • Google Cloud Messaging for Android
  • Google Cloud Pub/Sub
  • Google Cloud User Accounts
  • Google Play Android Developer API
  • Google Play Game Management
  • Google Play Game Services
  • Google+ API

You should be able to find them in the API Overview. When all of these are enabled (may not enable right away, just be aware of that), we have to check that you have Authentication Keys available for public use.
Go to the Credentials part of the Console and make sure you at least have an OAuth 2.0 Client ID for your game. If you do (I can’t help you with those) press the Add Credentials button and choose API Key. You should see something like this:


Press the “Server Key” button. Give it the name “Public API Key” and leave the IP Address list blank. Press Create. You should now have 2 keys. One of type Server and one of type Android.
Everything on the console should now be set up and ready to go.

Next Post will detail how to set up the project and Blueprints.


Lets have a look at the Blueprint and Project Settings part of this.

Open up your Blueprint project and go to the Project Settings. Go down into the Android settings.
You should already have “Enable Google Play Support” Checked and the Games App ID in the right field as well as the Google Play License Key in the right field (like mentioned earlier).

Now go up to the “Advanced APKPackaging” part of the settings. Add two extra tags to the “<manifest> node” and add the following lines:


Make sure you don’t have any weird spaces or hidden characters. It needs to be written exactly like the above.

When you’ve done that go to the “Extra Permissions” part and add four elements:

  • android.permission.INTERNET
  • android.permission.GET_ACCOUNTS
  • android.permission.USE_CREDENTIALS

Make sure you don’t have any weird spaces or hidden characters. It needs to be written exactly like the above.
With that added we need to add one more thing before we start mapping the Achievements and Leaderboards. Go to the top of the settings and press the “Open Build Folder” button. It will open the build folder of your project.

In there you should be able to find the “GooglePlayAppID.xml” file which is located at <PROJECT NAME>\Build\Android\res\values.

Open the GooglePlayAppID.xml file with any notepade editor. When you open it, usually all it will contain is this:

<?xml version="1.0" encoding="utf-8"?>
	<string name="app_id"></string>

In this line you add the Applications ID which can be found in your Project Settings in the “Games App ID” box that you have hopefully already filled in. Otherwise the ID is available in the Google Developer Console.

<?xml version="1.0" encoding="utf-8"?>
	<string name="app_id">YOUR GAMES APP ID HERE</string>

Now save and close the file. Go back into the Project and lets take a look at Achievements and Leaderboards.
For this to work you need the IDs like I mentioned earlier found in the Developer Console. So if you look at one of your achievements In the console you may find one called something like “Play a game!” with an ID that consists of a lot of characters and how many points it’s worth.
In the project settings go add a node to the Achievement Map. It will add a new child with two fields. In the first field put a name that makes sense to you. It’s not seen by the player but it’s an alias connected to the ID you put in the second field called “Achievement ID”. Do this for every achievement you have.

Now go to the Leaderboards section. It’s the same deal. You have a leaderboard and an ID to the leaderboard (both found in the Google Console). Add a node to the Leaderboard map and then add a name that you can remember (like HighScore) and the Leaderboards ID in the Leaderboard ID field.

You should now be all set to try and get this done in Blueprint now. So lets get to it!

At first we need to synchronize the user with the leaderboards. This is done fairly easy.
In my case I need to check if the leaderboard have a higher score than my local copy does and if it does change it. If it doesn’t however then I need to change the leaderboard value. It’s done like so:

The “Show External Login UI” should only be called if you know that the player isn’t online already. Otherwise it’s a wasted call for the end-user and will have to sit through the Google Play Services trying to login again even though the player is already logged in. Otherwise you can just skip that action and then go straight for the Leaderboard nodes. You can check if a player is online with this node:


If this returns True then you can skip the “Show External Login UI” node. If it returns False then you call it. This makes sure you only call for a login when it’s needed instead of every time you need to do this.

Moving on lets read some leaderboards. You may have noticed that in my first picture I have “Get Platform” and then go into a switch statement that differentiates between IOS and Android. This is specific to me but it’s relevant for you in case you want to make the game for both Android and IOS as it’s unlikely you are going to call your leaderboards the same across the “Game Center” service and the “Google Play” service. Just keep that in mind.

As I only use one GameMode I choose to store general functions I need to be able to call from different locations in my Game Mode as I can always get a reference to it. So I made the following blueprint nodes:

In the “Read Leaderboard Integer” you need to include a player controller. Usually just Player Index 0. Then in the State Name type the name of your leaderboard that you put in the Project Settings. In my case I called it HighScore. If your leaderboard is a Numeric Integer value like mine you will have the “Leaderboard Value” as output. If we assume you succeed then here is where the magic happens. My “Get Highest Score” node is a custom node that I made which looks in my local save file for the highest score I have recorded so far. If the score of the leaderboard is higher than the last recorded highest score, I set the score of my locally saved copy to the one I polled from the Leaderboard. That’s what I do in my custom node “Set Highest Score”.

However if the score I found on the Leaderboard is NOT higher than what I locally recorded I go to write the value to the leaderboard instead. Just like before in the “Read Leaderboard Integer” node you have to do the same in the “Write” but with one extra input being the new score to write to the leaderboard. Since this will be synchronized across devices as they are all tied to the same Google Account, don’t worry about overlaps or things like that.

Now our scores are synchronized so lets show the table as well.

Whatever way you want to trigger this, showing the actual board is very simple. You simply do this:


As you can see I included the name of my one Scoreboard “HighScore” as the Category Name. Now when your player triggers this it will open up the Google Play Services and then show you a leaderboard. You can read all about how Leaderboards work on the Google API Documentation and Help Sites. You CANNOT embed the leaderboard and you cannot control it’s layout nor how it shows. Google decides all of this. I know it’s a shame but in order to circumvent this, someone would have to do some serious work with a plugin and a JSON or REST plugin.

With this you should now have a working Leaderboard. Remember to check if the user is Online before you call the above node and if they aren’t, log them in. Also note that this may not work if you simply deploy from the editor to your phone or tablet. You may have to package an APK file and install on your device before it works. Also please be aware that the first time you use this Service it will ask you for permission before doing anything.

In terms of achievements however it’s a bit more tricky. What you do there is essentially pull a copy of the achievements down with this node:


So you have a local copy to work with. Then you call the following node:

And this is where things get tricky. What you would need to do is make an array of Achievement Names (that matches exactly with the ones you put in the Project Settings) and then iterate over the achievements you have as you see fit. Sorry I can’t say more on this but it’s still new to me how to work this part of Achievements.

Also if you just want to show achievements you just call this node:


No category needed.

Lets move on to In-App Purchases (IAP). In order to do these you need to set them up in the Google Developer Console first. Assuming you’ve done this take note of the name you put next to the item in the console itself. You can see it here:

Now go into your blueprint that is supposed to trigger the IAP dialog and put the nodes like this:


As you can see I put in the name that I showed above in the “Make InAppPurchaseProductRequest”. If your product is consumable (can be bought multiple times) you need to put a check in the “Is Consumable” box. But this function won’t work until 4.10 so just be aware of that.

Lastly lets look at AdMob.

Setting up AdMob is very simple. You go to your AdMob account and make a new Ad. It needs to be of type “Banner” and you can give it any name you want and allow any types in the Banner Category. When you’ve set that up you can see the banner in your overview screen and next to the banner there is an ID. You simply copy and paste that ID into the AdMob field found in the Android Project Settings and there you go.

Now you can call this node here:


And you can’t really control where it appears other than in the middle of the top of the screen or in the middle of the bottom of the screen.


Hi Vipar nice tutorial this helped me a lot

But i have a problem…my game keeps crashing on my S4 when i try to add the “show external login UI” in any blueprint. I tried in the game mode, player controller, in the menus and in the map bp but each time i call this node it crashes.
Any idea why?
I need this to work to make in app purchases leaderboards and achievements.

Edit: i found the problem…i forgot to enter the license key…it is working now thanks again for the nice tutorial!

It is most likely because you didn’t do this step:

I have often run into instant crash when using that node, if that step was not done. It happened yesterday too when I had to clean out some files so make sure you did that.

1 Like

Added In-App Purchases and AdMob section to the Tutorial.

Awesome tutorial!!. It really helped me, and my google play services are running perfect. Thanks for taking to time to do it!!


Mine is working perfectly without have to upload an alpha o Beta or any kind of apk for that matter , here is what I have done:
I started the game service from the developer console,
Add the package adress (com.yourcompany.yourappname) .
Add game detail (only required ones).
Add achievement (at least five - with required detail before publishing).
Now I think the trik is here:
I copied “get resource” completely to res/ values XML file
I also add each achievement to project setting>android
And then now I call UI login without any problem and for achievement the tappy chicken example seems fine for me so far…

I hope my experience could help some one.

I haven’t tampered with leader board yet so I don’t know anything about it yet

I’ve been having so many issues with this! I just found this today. I’m going to double check my work – thank you so much for your contribution.

I’m having some difficulties with getting logged in.

After loading the game to my phone using the Launch option I perform a “Is Logged In” check, which returns FALSE. I then prompt the “Show External Login UI” node – which does show both the account selection and Sign In page, but returns ON FAILURE. The App on occasion will seemingly restart after the ON FAILURE response.

I added the credentials as described and enabled all APIs as well added the permisions. (see images)

For my APP ID I only used the 12 digits, rather than the full string of alpha+numeric characters.


Did you remember to add the App’s ID to the string value file?

It was already present.

What’s the purpose of generating the API keys if they’re never used in the project?

I am not sure. It didn’t work when I didn’t have it so I assumed I had to have it. I came to this conclusion by looking at other Android Projects that had the same errors that I did (nothing to do with the Unreal Engine projects).
Let me see your blueprint please.

The UI to logon actually does show but I don’t ever get the ON SUCCESS response.

I’m going to tear down my entire Developer Console and start over since I set it up before your guide. - Nevermind, apparently you cannot remove apps from your console once published.

It’s weird. I tried my app today and I have been unable to connect to the Google Play Services as well and I didn’t change a thing. Maybe it’s an issue on Google’s side this time.

I’m going to be so mad if I tore apart my project for a google bug. You may want to note in your tutorial that you only include the digits in the APP-ID as well. Also, maybe a brief discussion of the application setup as well (first step)

Do you even have to upload an APK to get this to work?

Wonder if this has anything to do with it:

From what I understand it won’t allow you to do certain things in the developer console without a valid APK.

Vipar has been helping me troubleshoot my problem and we have found that an initial APK file should be uploaded as a shipment build so that it becomes signed with your keystore file. After which you can test locally by compiling shipping builds and pushing them to your phone.

You’ll need to make your own keystore file to do this. See for information on how to do this. Keytool can be found in your JDK\Bin folder. (default: C:\NVPACK\jdk1.7.0_71\bin)

Google Play Services will NOT work on development builds.

I already did mention this part somewhat:

You don’t actually need a build up on the Play Store. Leave it unpublished until you’re done testing. This will eliminate the four hour wait and allows you to remove your draft if you mess up somewhere (like me). It also lets you test without having to do a bunch of extra publishing work.

But then you if you leave it unpublished, it’s still uploaded. So my point still stands :slight_smile: