LoginWithCustomID in Unity

arn how to use the PlayFab Client library for Unity on Authentication mechanism discovery.

This QuickStart helps you make your PlayFab API call in the using the Client library for C# in Unity.
You can also review how to manage authentication in C# Console

You can found the full code on YAKAGameStudio/Learn (github.com)

Prerequisites

Before doing this tutorial, make sure you have:

Download & Install PlayFab SDK

Follow How to install PlayFab into Unity setup the prerequisites

Set up your Authentication Call

You want to go through the final step ? check this file on GitHub

  1. In Create a new Game Object, and rename it to PlayFab.
  2. In the Assets window, Right-click and select Create > C# Script. Name the script GetStarted.
  3. Add it to the Game Object as shown on the picture below.
  4. Double-click the file to open it in a code-editor.
  5. In your code editor, replace the contents of GetStarted.cs with the code shown below and save the file.

For this demo, all code lines will stay into the GetStarted.cs file. We will see later how to structure the authentication class

Initiate request header

To initiate your request, you should define how CustomID look like and behave.

var LoginRequest = new LoginWithCustomIDRequest
{
	// Your Title setup in PlayFab SDK
    TitleId = PlayFabSettings.TitleId,
   // Custom unique identifier for the user, use anything you want.
   CustomId = SystemInfo.deviceUniqueIdentifier,
   // Automatically create a PlayFab account if one is not currently linked to this ID.
   CreateAccount = true,
   // Request additional Information
   InfoRequestParameters = LoginRequestParams
};

You can also request additional information on login to initialize your game or your player profile.

For more information see : getplayercombinedinforequestparams

var LoginRequestParams = new GetPlayerCombinedInfoRequestParams
{
   GetPlayerProfile = true,
   GetUserVirtualCurrency = true
};

Call PlayFab API

You are ready to send your authentication request and catch the answer.

PlayFabClientAPI.LoginWithCustomID(LoginRequest, OnLoginSuccess, OnLoginError);

Manage PlayFab answer

We create 2 new functions that will print confirmation of the API call using messages written to the console output.

private void OnLoginSuccess(LoginResult result)
{
  Debug.Log("Congratulation, you are authenticated");
  Debug.LogFormat("Login Success: {0}", result.PlayFabId);
  Debug.LogFormat("Session: {0}", result.SessionTicket);
}

private void OnLoginError(PlayFabError error)
{
  Debug.LogWarning("Something went wrong with your first API call.  :(");
  Debug.LogError("Here's some debug information:");
  Debug.LogError(error.GenerateErrorReport());
}

You can extend the OnLoginSuccess with information requested with the LoginRequestParams. You want to review the full code source or detect an issue? Please use: YAKAGameStudio/Learn (github.com)

Conclusion

If you follow this step-by-step to perform LoginWithCustomID in Unity, you should have the following in your Unity Console

Share for immortality
Laurent LEFEVRE
Laurent LEFEVRE

I'm a Microsoft employee, working on Technology Strategy for large Enterprise account.
I focus on industry business trends and explain how you can leverage Azure Game Stack & Xbox services.
I assume that I don't know anything. This is a great habit to do a full knowledge refresh and avoiding bias.