title | author | description | ms.author | ms.date | ms.topic | ms.service | keywords | ms.localizationpriority |
---|---|---|---|---|---|---|---|---|
Title Data quickstart |
shikha-tarware |
Describes how to programmatically create and use title data |
shtarwar |
08/04/2020 |
article |
playfab |
playfab, remote configuration, title data, overrides |
medium |
Title data is the set of plain text key-value pairs, used for storing and managing the game’s configuration data remotely on the server. It keeps the title wide configuration variables accessible and organized which can be retrieved on the client-side.
This QuickStart describes how to programmatically create and use title data.
This an important topic because storing a game's configuration data remotely on the server - where it can be changed at any time - is one of the most basic reasons to use a service like PlayFab.
Use GetTitleData from the PlayFabClientAPI
to get the KVPs for a specific title. The following code example displays the values of all of the title data.
public void ClientGetTitleData() {
PlayFabClientAPI.GetTitleData(new GetTitleDataRequest(),
result => {
if(result.Data == null || !result.Data.ContainsKey("MonsterName")) Debug.Log("No MonsterName");
else Debug.Log("MonsterName: "+result.Data["MonsterName"]);
},
error => {
Debug.Log("Got error getting titleData:");
Debug.Log(error.GenerateErrorReport());
}
);
}
Use GetTitleData from the PlayFabServerAPI
to get the KVPs for a specific Title. The following code example displays the values of all of the Title Data.
public void ServerGetTitleData() {
PlayFabServerAPI.GetTitleData( new GetTitleDataRequest(),
result => {
if (result.Data == null || !result.Data.ContainsKey("MonsterName")) Debug.Log("No MonsterName");
else Debug.Log("MonsterName: " + result.Data["MonsterName"]);
},
error => {
Debug.Log("Got error getting titleData:");
Debug.Log(error.GenerateErrorReport());
});
}
It is unlikely that title data will change very frequently. For most situations, you should use your title data for static data that is mostly unchanged for the life of the title.
You can set title data by using the Game Manager, or by a server API function.
To add Primary Title Data using Game Manager to a title, perform the following steps.
- Open the title in Game Manager.
- Select Content, then Title Data.
- Select New Title Data
- In the new title data page, enter a value for the Key and a value for the Value. Both the Key and the Value are stored as strings.
- Use the Save button to save the new data item.
The SetTitleData API is a server API that you must call from a dedicated server. You can only set one title data KVP in each call to SetTitleData
.
public void SetTitleData() {
PlayFabServerAPI.SetTitleData(
new SetTitleDataRequest {
Key = "MonsterName",
Value = "Dorf"
},
result => Debug.Log("Set titleData successful"),
error => {
Debug.Log("Got error setting titleData:");
Debug.Log(error.GenerateErrorReport());
}
);
}
An override is also a set of JSON key-value pairs and ideally should be purposed to possess the delta change required in the key-values pairs of the Primary Title Data. The delta change could comprise of the key-value pairs when compared to Primary Title data as new key-value, change in an existing key’s value or deletion of a key (with NULL as an input of the value).
To add overrides to the primary title data, perform the following steps.
- Open the title in Game Manager.
- Select Content, then Title Data.
- Select New Override.
- Enter the Override Label, plus, enter a value for the Key and a value for the Value. Both the Key and the Value are stored as strings.
- Use the Save button to save the new Title Data Override.
Note
This override set of key/value pairs comes in-effect only using Experiments for now. If the player belongs to an experiment variant which contain title data overrides, the overrides are applied automatically on server side and returned with the title data on client side. Title Data Override values may take up to one minute to refresh and persist.
Similarly to User Data, title data has internal storage that is hidden from the client. This data can also be set in the Game Manager, or via a server API.
public void GetTitleInternalData()
{
PlayFabServerAPI.GetTitleInternalData( new GetTitleDataRequest(),
result => {
if (result.Data == null || !result.Data.ContainsKey("PlayFab")) Debug.Log("No PlayFab");
else Debug.Log("PlayFab: " + result.Data["PlayFab"]);
},
error => {
Debug.Log("Got error getting titleData:");
Debug.Log(error.GenerateErrorReport());
}
);
}
public void SetTitleInternalData() {
PlayFabServerAPI.SetTitleInternalData(
new SetTitleDataRequest {
Key = "PlayFab",
Value = "{ \"Status\": \"Secretly Awesome\" }"
},
result => { Debug.Log("Set titleData successful"); },
error =>
{
Debug.Log("Got error setting titleData:");
Debug.Log(error.GenerateErrorReport());
});
}