Integrate Google Play Services with Blueprint

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:

  • com.google.android.gms.games.APP_ID=“@string/app_id”
  • com.google.android.gms.appstate.APP_ID=“@string/app_id”

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:

  • com.android.vending.BILLING
  • 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"?>
<resources>
	<string name="app_id"></string>
</resources>


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"?>
<resources>
	<string name="app_id">YOUR GAMES APP ID HERE</string>
</resources>


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:

bfd80194be.png

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:

af82c05036.jpg

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:

02b418f82d.png

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:

b0e78de58262830ccaa6ad8f6fc868e08d4add3a.jpeg

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:

bfd80194be.png

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:

0f01792af2cec0695b9b975ed4475dcbe45b05f4.jpeg

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.

3 Likes