Use the Player Accounts Unity Building Block to add sign-in functionality to your project, for example, to track and preserve users’ progress in your application. To learn more about PLayer Accounts, refer to the Player Accounts documentation.
This Building Block includes a test sceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary that demonstrates the player authentication process. You can use the scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
See in Glossary in this Building Block to authenticate players in your own project. For more information, refer to Add the Player Accounts Building Block to a different scene.
The Player Accounts Building Block uses the following Unity Gaming Services (UGS):
| Unity Gaming ServiceTopic | Description |
|---|---|
| Authentication | Assigns each player a unique identity. To use these authentication flows, (set up an identity provider)[set-up-an-identity-provider]. To learn more, refer to Authentication. |
| Cloud Save | Stores Player Data and Game Data for your games, and provides access classes to control read and write access to Player Data and protected Game Data. To learn more, refer to Cloud Save. |
| Cloud Code | Provides server authority that you can use to write to protected or private access classes. You can use Cloud Code to write to game data or protected player data, or to read private game data. To learn more, refer to Cloud Code Authentication. |
To set up a project for the Player Accounts Building Block, follow the instructions in:
To use all features of the Player Accounts test scene, follow the steps in this section.
The Player Accounts Building Block test scene demonstrates multiple sign-in methods. For your project to recognize these authentication methods, do the following:
The test scene uses the BlocksGameModule.ccmr Cloud Code module to update the global score which is the result of the values of all authenticated players added together. To use this Cloud Code module, deploy it:
The Player Accounts Building Block test scene demonstrates the following steps in a player account workflow:
PlayerAccountScene.uxml asset declare.BlocksGameModule.ccmr Cloud Code module manages.To open the Player Accounts Building Block test scene:
PlayerAccountScene asset and select Open.To use the Player Accounts Building Block test scene:
Note: The Authentication service stores player identity on the cloud.
To add player authentication from the Player Accounts building block to a new scene, do the following:
1. Deploy the Cloud Code module.
2. Go to Assets > Blocks > Achievements > Prefabs.
3. Select the AchievementsPrefab to open it.
Any changes you make to Achievements.ach affect the AchievementsPrefab when you enter Play mode.
You can also add the Player Accounts user interface assets to a different scene. To learn more, refer to Customize the Player Accounts user interface.
Note: To create a new Achievements Configuration file, go to Create > Blocks > Achievements Configuration.
The player accounts starter scene contains the following scripts that you can modify to change how player authentication works in the scene:
The Player Accounts Building Block contains Unity Extensible Markup Language (UXML) assets to display the test scene user interface (UI). To learn about UXML scripts, refer to Introduction to UXML.
To customize the Player Accounts user interface:
To learn more about UI builder, refer to UI Builder.
The Player Accounts Building Block contains the following Unity Extensible Markup Language (UXML) assets that you can modify or add to a different scene.
| Asset name | Description |
|---|---|
PlayerSignIn |
Displays authentication options that you can use to sign in anonymously, with Unity’s Player Account web portal, or with a username and password. To learn more, refer to Platform-agnostic authentication. |
PlayerIdLabel |
A reusable label that displays and tracks the player ID with clipboard integration. |
PlayerNameLabel |
A reusable, data-bound label that tracks the player name. You can edit the name in the UXML field in the test scene. |
PlayerDataLabel |
A reusable label that loads Public, Default, or Protected player data according to the assigned data-key attribute. |
PlayerEditableDataLabel |
Specialized PlayerDataLabel that allows editing player data (except for Protected). |
PlayerLoadDataControl |
Debug control that displays all available default access class keys, and loads the value of one on demand for the player. |
The Player Accounts UXML scripts use the following classes:
AuthenticationService from the Authentication package.ServiceObserver&T from the Services Core package.
The Player Accounts Building Block contains scripts that manage player data, such as sign-in information, and game data, for example, scores. These scripts use the ServiceObserver<T> base class, which you can use from the Services Core package, to manage the lifetime of services without the need to track them manually.
Find the following script assets in the Project window: Assets > Blocks > PlayerAccount > Scripts > Runtime.
| Asset name | Description |
|---|---|
AuthenticationObserver |
Handles sign-in events and authentication state, and allows the project to register callbacks. |
CloudDataContainer |
Displays the information that AuthenticationObserver stores in the test scene. This container also manages asynchronous player data loading and binding that you can instantiate and access in a script. |
GlobalScoreClient |
A Cloud Code module file that uses a write lock mechanism to manage game-level shared data samples of a global score. |
If the Increment Global Score button in the Player Accounts test scene doesn’t update the Global Score value, follow the instructions to deploy the Cloud Code module.
To learn more about read and write restrictions for Cloud Save Data, refer to the Services API documentation.