Setting up PlayFab authentication using Kongregate and Unity
This tutorial shows you the minimal setup required to authenticate your players in PlayFab, using Kongregate and Unity.
- A registered Kongregate account.
- Familiarity with the Kongregate Developers Guide.
- A registered PlayFab title.
- A Unity project with PlayFab configured for your title.
- Unity WebGL support installed.
- Familiarity with Login basics and Best Practices.
Setting up a Kongregate app
Kongregate requires you to upload a preview version of the app, before you gain access to the necessary app information. Our first step is to prepare an index.html file with the content shown below.
<!doctype html> <html lang="en-us"> <head></head> <body> <h1>Placeholder</h1> </body> </html>
Navigate to the Kongregate website.
- Select the Games tab.
- Then select the Upload your game button.
A page to set up a new application will open.
- Make sure to enter the Application Name.
- Enter a Game Description.
- Then select a Category.
- Submit the new app by selecting the Continue button.
You will be transferred to the Application Upload page.
First - and most importantly - make sure to save the URL from your Web Address Bar in a safe and easily accessible place. This will save you a lot of time restoring access to the application once you close the page.
- Once this is done, select the prepared index.html file as your Game File.
- Then set up the screen size.
- Make sure to accept all the required licenses.
- Finally, upload your application by selecting the Upload button.
Once the preview opens, ignore the content and open the api information link.
When the API Information page opens, locate the API Key and keep it in a safe place that is easily accessible for later use.
Configuring PlayFab title
In your PlayFab title Game Manager:
- Select Add-ons from the menu on the left.
- Locate and select the Kongregate icon.
A new page will open, allowing you to set up Kongregate integration:
- Enter the API Key you acquired in the previous section.
- Select the Install Kongregate button.
At ths point, if you do not receive an error message, you have configured PlayFab title integration with your Kongregate application properly.
Setting up a Unity project
Use this Unity setup checklist:
- [OPTIONAL] Install the PlayFab Editor Extensions.
- Set up your
- Set up your
- For Unity 5.6+, download the Kongregate Preloader WebGL Template, and place it inside the
- For Unity < 5.6, download the Kongregate Preloader WebGL Template 5.5 and below, and place it inside the
Now let's create your working scene.
- For testing purposes, use a screen-scaling canvas with a couple of text labels.
We will only need one text label to display debug messages.
- Create an empty GameObject, and rename it to Kongregate.
GameObject will contain a
KongregateHandler component with a wired text label for debug messages.
The code for the
KongregateHandler component is provided below.
The only way you can truly test the integration is by uploading your prototype to Kongregate.
- Open the Build window and make sure WebGL is selected from your menu.
- Then open the Player Settings by selecting the button.
Inside the Player Settings screen, locate the Settings for WebGL build:
- Verify that you have the size set up correctly.
- Then select the Kongregate Preloader Template.
Build the application and open the Build folder.
- You will end up with index.html and a bunch of other files (depending on Unity version).
- Take all the files except index.html and place them inside a zip archive, as shown in the example provided below.
Use the URL you saved earlier to access your Application Upload page.
- Select index.html as your Game File.
- Then select the zip archive as Additional files.
- Accept the licenses and upload.
Once the preview opens, you should be able to see your game live as the message changes.
At completion, the message should indicate successful login through PlayFab.
At this point, you have successfully integrated PlayFab and Kongregate.