> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart Player Data

> PlayFab Player Data quickstart shows how to create, read, and update custom player key-value fields from client and server SDKs step by step.

# Quickstart: Set and get player data

<Note>
  In the PlayFab APIs, the function names utilize the term **UserData**. In the **Game Manager**, this concept is described as **Player Data**. They're identical, and interchangeable.
</Note>

Get started using PlayFab Player Data. This quickstart shows you how to set and retrieve player data using C# in Unity and using PlayFab CloudScript.

Player data is information that applies to an individual player or player group (shared data) and is stored as Key/Value Pairs (KVPs) by PlayFab. This article covers client API calls, which are safe to call from any process or context. It also covers server API calls, which should *only* be made from a dedicated server process you control, or a carefully secured CloudScript call. Server APIs require your dev secret key. The key shouldn't be provided to, or published with, your client.

## Requirements

* A [PlayFab developer account](https://developer.playfab.com).
* An installed copy of the Unity Editor. To install Unity for personal use via Unity Hub, or Unity+ for professional use, see [Download Unity](https://unity3d.com/get-unity/download).

<Note>
  The PlayFab Unity3D SDK supports Unity Editor version 5.3 (released December 2015) and higher.
</Note>

* A Unity Project can be:
  * A brand new project. For more information, see [Starting Unity for the first time](https://docs.unity3d.com/550/Documentation/Manual/GettingStarted.html).
  * A guided tutorial project. For more information, see [Getting Started with Unity](https://learn.unity.com/).
  * An existing project.
* The PlayFab Unity3D SDK.

For information about setting up the PlayFab Unity3D SDK, see [Quickstart: PlayFab Client library for C# in Unity](/services/playfab/sdks/unity3d/quickstart) article. This article ensures that you have a PlayFab account and that you correctly configured the Unity3D SDK.

## About the code examples

The C# Samples in this article are written for the Unity SDK. The Unity SDK uses an event driven model to handle non-synchronous tasks. To run the sample code using the C# SDK, you must modify the code to use an async Task model. Methods that must be modified have Async appended to the method name in the signature. For example, SetObject in the Unity SDK becomes SetObjectAsync in the C# SDK. For more information, see [Asynchronous programming with async and await](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/).

Although you can use an existing Unity project, this quickstart assumes you're using the sample created when you complete the [Quickstart: PlayFab Client library for C# in Unity](/services/playfab/sdks/unity3d/quickstart).

## Player data in Game Manager

You can always get and set player data through Game Manager by performing the following steps.

* Open **Game Manager**. If you're unfamiliar with it, see the [Game Manager quickstart](/services/playfab/live-service-management/gamemanager/quickstart).
* Select the **Players** tab.
* Select the name of the **Player** to access the **Players Account** tab.
* Select the **Player Data** tab to see their data.

## Add a method to set the player data and retrieve the player data

1. In the Unity Editor, open your sample project.

2. In the **Project** window, open **Assets** > **Scripts** and then open the PlayFabLogin script.

3. In Visual Studio, add the following to the using statement:

   `using System.Collections.Generic;`

4. To set player data, add a `SetUserData` method to the `PlayFabLogin` class. `SetUserData` uses the [UpdateUserData](xref:titleid.playfabapi.com.client.playerdatamanagement.updateuserdata) method to create or update the player data for the logged in player.

   The method creates (or updates, if the Key Value Pairs (KVPS) already exist) the KVPs `Ancestor` with the value `Arthur`, and `Successor` with the value `Fred`.

   ```csharp theme={null}
   void SetUserData() {
       PlayFabClientAPI.UpdateUserData(new UpdateUserDataRequest() {
           Data = new Dictionary<string, string>() {
               {"Ancestor", "Arthur"},
               {"Successor", "Fred"}
           }
       },
       result => Debug.Log("Successfully updated user data"),
       error => {
           Debug.Log("Got error setting user data Ancestor to Arthur");
           Debug.Log(error.GenerateErrorReport());
       });
   }
   ```

5. To get player data, add a `GetUserData` method to the `PlayFabLogin` class. `SetUserData` uses the [GetUserData](xref:titleid.playfabapi.com.client.playerdatamanagement.getuserdata) method to retrieve the player data for the specified player.

   ```csharp theme={null}
   void GetUserData(string myPlayFabId) {
       PlayFabClientAPI.GetUserData(new GetUserDataRequest() {
           PlayFabId = myPlayFabId,
           Keys = null
       }, result => {
           Debug.Log("Got user data:");
           if (result.Data == null || !result.Data.ContainsKey("Ancestor")) Debug.Log("No Ancestor");
           else Debug.Log("Ancestor: "+result.Data["Ancestor"].Value);
       }, (error) => {
           Debug.Log("Got error retrieving user data:");
           Debug.Log(error.GenerateErrorReport());
       });
   }
   ```

6. Call `SetUserData` and `GetUserData` in the `OnLoginSuccess` method.

   ```csharp theme={null}
   private void OnLoginSuccess(LoginResult result) {
       Debug.Log("Congratulations, you made your first successful API call!");
       SetUserData();
       GetUserData(result.PlayFabId);
   }
   ```

7. Save the file.

## Run the sample

In the Unity Editor, select the play button. On success, the results of the calls display in the console window.

## See Also

* [How to set internal player data](/services/playfab/player-progression/player-data/how-to-set-internal-player-data)
* [How to get internal player data](/services/playfab/player-progression/player-data/how-to-get-internal-player-data)
* [How to set read-only player data](/services/playfab/player-progression/player-data/how-to-set-read-only-player-data)
* [How to get read-only player data](/services/playfab/player-progression/player-data/how-to-get-read-only-player-data)
* [How to modify read-only or internal player data from CloudScript](/services/playfab/player-progression/player-data/how-to-modify-read-only-internal-player-data)
* [Title Data quickstart](/services/playfab/live-service-management/game-configuration/titledata/quickstart)
* [Using Publisher Data](/services/playfab/live-service-management/game-configuration/titledata/using-publisher-data)
* [CloudScript quickstart](/services/playfab/live-service-management/service-gateway/automation/cloudscript/quickstart)


## Related topics

- [Title Data quickstart](/services/playfab/live-service-management/game-configuration/titledata/quickstart.md)
- [Player Custom Properties Quickstart](/services/playfab/live-service-management/game-configuration/segmentation/player-custom-properties-qs.md)
- [Data Explorer quickstart](/services/playfab/data-analytics/learn-data/data-explorer/quickstart.md)
- [Player Inventory Quickstart](/services/playfab/economy-monetization/economy-v2/inventory/quickstart.md)
- [Data Connections quickstart](/services/playfab/data-analytics/export-data/data-connection-quickstart.md)
