Get Started
Download
You must imperatively have the playfab SDK in your project. This is a service that will be used to store all player data. Normally this one is attached in the asset, but if you encounter errors delete it and download it here.
Configuration
-
Step 1: Create a PlayFab Application
Congratulations, you are now connected to the Play Fab services, all you have to do is create your application, to do so, simply follow the steps indicated. You should have this:
-
Step 2: Configure your PlayFab Application
Now click on your game to access this information, then follow this video.
This step is very important, it will allow users to store their data.WARNING by checking this box, your game can be submitted to cheat!
So follow this step only if you want unsecured data transfer. -
Step 3: Get your Application ID
Now, all you have to do is retrieve your game ID, in the settings, from where you were:
Copy your Title ID to your clipboard and proceed to the next step. -
Step 4: Unity Pre-Configuration
So, now you can go back to Unity to set up your project. In the action bar, go to Database Controller > Settings
This window should then open:
-
Step 5: Unity Configuration
Go to the scene you will use for your connection system.
ATTENTION only one scene can be used per project to avoid any problems.
Then, in the settings window that was opened earlier, click the “Create this object for me” button. After which, you can enter your application ID (step 3) in the Project ID selection.
If you are developing a mobile game, and would like to use the anonymous connection option, please switch your project to iOS or Android if you haven’t already done so. This option is only available for mobile.
Now all you have to do is fill in all the necessary objects in the management window and press “Apply”.
A confirmation message should appear in the Unity console.
Congratulations, you have successfully configured your project.
Now you can build your level in order to implement the login system for the user.
You can help yourself from the demo scene to better understand.
Implementations (Unity C#)
During this part, you will be able to see some implementations that you may not use in your project, if so, just skip the part in question.
1 - Get Started
In order to properly prepare your system, you will need only one thing, a script that will manage the elements of your scene.
If you have a problem or hesitation, do not hesitate to consult our demo script, or join us on discord.
Step 1:
Open your script, and at the top, insert the following line : ‘using DatabaseAPI.Account;’
(this is our demo script, you can find it in the asset folder > Demo > scripts).
Now, you're able to use our asset in your script.
ATTENTION more namespace can be used, refer to the Extras part of this documentation.
2 - Connection
Step 1:
Once the API is imported into your script, you can create your first calling functions.
Here are the available instructions:
-
1 - Get the username of the person to be registered (Complete void bellow)
public void GetUserName(string value) { AccountController.controller.GET_USER_USERNAME(value); }
-
2 - Get the email address of the user to connect/register (Complete void bellow)
public void GetUserEmail(string value) { AccountController.controller.GET_USER_EMAIL(value); }
-
3 - Get the password of the user to log in/register (Complete void bellow)
public void GetUserPassword(string value) { AccountController.controller.GET_USER_PASSWORD(value); }
-
4 - Send a connection request (line 176 in demo script)
AccountController.controller.LOGIN_ACTION();
-
5 - Send an account creation request (line 178 in demo script)
AccountController.controller.ON_CLIC_CREATE_ACCOUNT();
-
6 - Send a Logout Request (line 182 in demo script)
AccountController.controller.LOG_OUT();
Step 2:
All right, now, save and go back to unity to link these new functions to your buttons.
The first 3 functions listed above must be added to InputFields, in the “On Value Changed” section.
CAUTION choose the Dynamic string, otherwise your function will not work.
ATTENTION be careful, it's not necessary, but you can select the true option in Content type, Email Address for email, Password for the password, and standard for username.
Now, you just have to put the login or connect function to your button in the on Click function.
3 - Mobile Anonymous Connection
If you dont made a mobile game, please skip this part
This anonymous login allows the user to start playing without creating an account. The anonymous login still create an account to the user, which will allow him an automatic login every time the application opens. Its ID and password will be defined by its phone ID. Using the anonymous connection does not prevent linking your profile to an existing account or a new one afterwards.
If you want to use this option, you don’t need a connection scene, you are strongly advised to do this section in your main menu scene.
Prerequisites:
in your scene, main menu for example, you will need a button to open the backup account section, and a panel that will allow the user to enter this data (email, and password as well as a username, which will only be processed if the connection does not work).
Step 1: Write the new functions in your script
-
1 - This first command is simply used to open your connect recovery panel.
public void OpenCloseRecoverySection() { AccountController.controller.OPEN_RECOVERY_PANEL(); }
-
2 - Now, this function is used to request a recovery connection, like on a login button
public void CreateRecoveryAccount() { AccountController.controller.ON_CLIC_ADD_RECOVERY(); }
4 - User Statistics (unsecure)
You can only save integer (int) values!
The first thing to know, is that when connecting, all user data is stored in a local dictionary.
You can view it and retrieve this data by simply typing:
AccountController.playerData.TryGetValue(NAME OF THE VALUE SAVED, out VALUE TO UPDATE)
You can see this template in the demo script, line 64.
How to save new data or update one:
AccountController.controller.SetStat(NAME OF THE VALUE TO SAVED, VALUE TO SAVE);
You can see this template in the demo script, line 104.
5 - User Statistics (securized)
The first thing to know, is that when connecting, all user data is stored in a local dictionary (the same as the previous section).-
1 - Configure your PlayFab Cloud Script (Js)
First, if you are using the backup method from the previous section, go back to the PlayFab settings, and uncheck the “Allow client To post player statistics” box in API Features.
(made the opposite of the step 2 in the configuration section)
Next, configure your cloud script.
On your project dashboard, go to “Automation” and then choose “Revisions” in the “Cloud Script” section:
Once this is done, you can start writing.
If you have never touched your revisions, you can delete all its content, and write:
handlers.UpdatePlayerStats = function (args, context) {
var request = {
PlayFabId: currentPlayerId, Statistics: [{
StatisticName: STATISTIC NAME SHOWED IN USER PROFILE,
Value: args.STATISTICS ARGUMENT TO PUT IN YOUR UNITY SCRIPT
}]
};
var playerStatResult = server.UpdatePlayerStatistics(request);
return{messageValue: "Updated Statistics"}
};
This is the function used for the demo script. -
2 - Implementation in your script
Note:
It is recommended that the NAME OF THE VALUE SAVED be identical to the STATISTIC NAME SHOWED IN USER PROFILE defined earlier.AccountController.playerData.TryGetValue(NAME OF THE VALUE SAVED, out VALUE TO UPDATE)
You can see this template in the demo script, line 64.
How to save new data or update one:public int userLevel; // user data variable
public void UpdateLevel(int value)
{
userLevel += value // update the variable
StartUpdatePlayerStatsSecure(); // call the cloud script update function
}
private void StartUpdatePlayerStatsSecure()
{
if (AccountController.controller.secureDataSave)
{
PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest()
{
FunctionName = "UpdatePlayerStats", // cloud function name
FunctionParameter = new { CLOUD SCRIPT ARGS NAME = userLevel },
GeneratePlayStreamEvent = true, // Optional - Shows this event in PlayStream
}, AccountController.OnCloudUpdate, AccountController.OnErrorShared);
}
}Note:
With the use of the Cloud Script, your CLOUD SCRIPT ARGS NAME need to be identical to the STATISTICS ARGUMENT TO PUT IN YOUR UNITY SCRIPT defined earlier.
6 - Friends
Letting players connect with their friends is a great engagement tool for your game! PlayFab offers you the ability to manage your own custom friends lists within your game.Any player in your title may be friends with any other player in your title. Notably, friendship on PlayFab is a one-way street.
If Julie adds Bob as a friend, there is no approval process for Bob. In fact, Bob may be unaware.
Bob must separately add Julie for the friendship to be mutual.
If you wish to have reciprocity rules, it is your title's responsibility to enforce these conditions with a custom game server or CloudScript logic, if necessary, but this is not yet integrated into this asset.
This friendship system is also compatible with some services like Photon. A new update should soon be available, this asset will incorporate direct compatibility with these services, so friend systems will no longer be one-way, and you can easily integrate an approval system.
But for now, You must develop this method alone.
If you need help, don’t hesitate to join us on discord.
To start, you need to make your friend panel, you can recover the one from the demo scene. Then, in the asset settings window, go to the “Friends” section and fill all the fields.
For the “Friend listing prefab”, you can use the demo one.

Then click “Apply” to save the selection.
Once that is done, it is time to code. Rest assured, you will only have one or two minutes.
First, you need to choose a method of adding friends.
Four methods are pre-built: Add by Play Fab ID, add by email, add by account username, and add by user name displayed in game.
The calls are respectively:
FriendsController.SubmitFriendRequestWithID();
FriendsController.SubmitFriendRequestWithEmail();
FriendsController.SubmitFriendRequestWithUsername();
FriendsController.SubmitFriendRequestWithDisplayName();
These functions require a parameter, a string that will contain either the user’s ID, or his email, etc.
For example:
using DatabaseAPI.Multiplayer; public string friendsID; public void UpdateFriendSearchID(string FriendID) { friendsID = FriendID; } public void AddFriend() { FriendsController.SubmitFrienRequestWithID(friendsID); } public void OpenCloseFriends() { FriendsController.OpenCloseFriendsPanel(); } |
Find this model line 218 to 231 of the demo script.
7 - Leaderboard
Leaderboards are essentially rankings of entities such as players. A leaderboard ranks a list of entities based on their respective values. For example, “High Scores” is one of the most common implementations of leaderboards.Two types of leaderboards are available in this asset, a global leaderboard, for example to show the player, the best worldwide based on a precise statistic, the best score in the demo scene.
And a friend leaderboard, which shows the ranking of friends according to a statistic, here again, this is the best score that is used in the demo scene.
-
1 - Global leaderboard
Before you start, make sure you have prepared your scene and fill in the corresponding section in the asset settings window:
For the leaderboard listing prefab, you can use the one integrated in the asset, in the Prefabs folder.
Once this is done, you can start coding, everything is already ready, you only have two functions to call:using DatabaseAPI.Multiplayer;
public void OpenLeaderboard()
{
LeaderboardController.OpenLeaderboard(STAT NAME, MAX USER TO DISPLAY);
}
public void CloseLeaderboard()
{
LeaderboardController.CloseLeaderboard();
} -
2 - Friends leaderboard
Again, configure the settings in the editor window
For the leaderboard listing prefab, you can use the one integrated in the asset, in the Prefabs folder.
Once this is done, you can start coding, everything is already ready, you only have two functions to call:using DatabaseAPI.Multiplayer;
public void OpenFriendsLeaderboard()
{
LeaderboardController.OpenFriendsLeaderboard(STAT NAME, MAX USER TO DISPLAY);
}
public void CloseFriendsLeaderboard()
{
LeaderboardController.CloseFriendsLeaderboard();
}
8 - Virtual Currency
Most games support at least two virtual currencies. Many use a “soft” currency that can be earned in-game through play, and a “hard” currency that can be bought. Having dual currencies gives you more control over your economy, since you can determine which items can be bought.
See official PlayFab tutorial on Currencies.
Step 1: Create your virtual currency in PlayFab Dashboard

Then, follow the instructions.
Step 2: Update your Cloud Script
On your project dashboard, go to “Automation” and then choose “Revisions” in the “Cloud Script” section:
Once this is done, you can start writing:
handlers.AddCurency = function (args, context) { server.AddUserVirtualCurrency({PlayFabId: currentPlayerId, VirtualCurrency: args.money, Amount: args.amount}); return{messageValue: "+" + args.money + " currency"}; }; handlers.SubCurency = function (args, context) { server.SubtractUserVirtualCurrency({PlayFabId: currentPlayerId, VirtualCurrency: args.money, Amount: args.amount}); return{messageValue: "-" + args.money + " currency"}; }; |
Step 3: Implementation in Unity
To get started, you need to enable the use of virtual currencies in the editor window.Go to: Database Controller > Settings > Virtual Currency > Enable virtual currency > Apply
-
How to recover the value from playfab
You should know that your virtual currencies are then stored in a 'virtualcurrency' dictionary, so you can access it at any time, this dictionary is updated each time you log in, or you change one of these values, which will also change it in PlayFab.
So, to get your currency, you just need to type:
AccountController.controller.virtualCurrency.TryGetValue(CURRENCY CODE, out VARIABLE TO PUT THE VALUE);
Find this model line 83 of the demo script. -
How to update the currency
Only one method, everything is ready for you:
AccountController.UpdateCurrency(CURRENCY CODE, AMOUNT, ADD OR SUBTRACT);
Find this model line 122 of the demo script.
Note:
The AMOUNT to add need to be greater than 0.
If you want to add the value, turn the third parameter (ADD OR SUBTRACT) to true, or if you want to subtract the amount to the player, turn it to False.
9 - User Data (under development)
More informations.
Note: You can analyze the demo scene and its script to understand how this part works.
The following code corresponds to the one you can find in the demo script, from lines 247 to 293.
The SetUpStore function lets you know which skins have already been purchased by the player.
Then, the UnlockSkins function and the one that will be associated with a button to unlock the skin associated with this button.
And finally, the SetThisSkin function allows you to equip one of the skins.
public void SetUpStore() { for (int i = 0; i < PersistantData.pd.allPlayserSkins.Length; i++) { buttonsLock[i].SetActive(!PersistantData.pd.allPlayserSkins[i]); unlockedButtons[i].interactable = PersistantData.pd.allPlayserSkins[i]; } } public void UnlockSkin(int index) { int price = 0; if (index == 1) price = 100; else if (index == 2) price = 200; else if (index == 3) price = 300; else if (index == 4) price = 400; else if (index == 5) price = 500; else if (index == 6) price = 600; if (money >= price) { UpdateMoney(-price); PersistantData.pd.allPlayserSkins[index] = true; AccountController.controller.SetUserSkinsData(PersistantData.pd.SkinsDataToString()); SetUpStore(); } else { AccountController.controller.SendDebugMessage("Not enought money"); Debug.Log("Not enought money"); } } public void SetThisSkin(int index) { PersistantData.pd.currentSkin = index; } |
Extras
In this last part of the Asset manual, you can find several small functions that may be useful to you.
-
1 - Knowing when you are logged into an account
You can say that this option has no interest, but on the contrary, it’s necessary! When you log in, how do you know if that connection failed, and therefore how do you make sure that you can start the next scene, such as a main menu.
To access this information, you have this boolean available:
AccountController.controller.connectedToAnAccount
If you are logged in, this boolean will return True.
If you are looking for how to integrate it, you can consult the demo script of line 53 to 60. -
2 - Know when data has finished loading
Looking at these lines 53 to 60 of the demo script, you must have seen this:
AccountController.controller.getStatsFinished
This statement is also a boolean. It allows to know the state of loading of the user’s data. This boolean will equal True when all data is finished loading.
This option allows for example the use of a loading screen, to avoid that once logged in, the user sees erroneous data because not yet updated. -
3 - Retrieve errors
It’s also one of the most important elements, how to warn the user of a failure.
To do this, you have access to a variable that will allow you to directly retrieve the entire error message:
AccountController.DebugMessage
this simple command allows you to retrieve the error message, then you can either process it or return it as it was to the user.
Example of use:
public Text errorMsg; // using UnityEngine.UI;
void Update() { errorMsg.text = AccountController.DebugMessage; }
If you want to send your own debug message, just type:
AccountController.controller.SendDebugMessage(YOUR MESSAGE); -
4 - Get the User ID
Do you need your player’s server ID? you can retrieve it by typing AccountController.userID
User Id is a string that will contain the id of the currently connected player.
You can find it in the demo script, from lines 69 to 76. -
5 - Get the User Name
Do you need your player’s Name? you can retrieve it by typing AccountController.userName
User name is a string that will contain the id of the currently connected player.
-
6 - Namespace error
If you have errors about not having access to some scripts, check that you are using the correct namespace
Here are the different namespace you may need:
using DatabaseAPI.Multiplayer;
using DatabaseAPI.Account;
using DatabaseAPI.Data;
using PlayFab;
How to use PlayFab dashboard
-
1 - Accessing Users
-
2 - View his data
Once on the players reference page, click on one of the list to access their profile.
Once on a profile, the Overview page references this personal data, then the Statistics section will show you its data that you have chosen to save online, and finally, the Logins section will show you these latest connections.
The other sections will probably not be useful to you with this asset, as they are not compatible.
To go to your dashboard, in the unity action bar go to: Database Controller > Your Dashboard