Documentation

Did you find this helpful?

Using Title Data

This document 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 why to use a service like PlayFab.

Title data is represented as key/value pairs (kvps) that can only be associated with a specific title.

NOTE: Title Data values are copied and distributed to potentially hundreds of machines in the PlayFab cluster server. As part of this process, Title Data is cached and changes may take upto fifteen minutes to refresh in those caches. Title Data is best suited for "global constant/static data", and is not suitable or reliable as "global variables".

Getting Title Data

From the game client:

Use GetTitleData 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());
        }
    );
}

From the game server:

Use GetTitleData 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());
        });
}

Setting Title Data

It is unlikely that Title Data will change very frequently. For most situations, you will want to 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. After the Title Data is set for initial release, most titles will not make significant changes from that point.

Setting Title Data Using Game Manager:

To add data to a title, perform the following steps..

  • Open the title in Game Manager.
  • Click Content, then Title Data.
  • Click Add Item.
  • Enter a value for the Key and a value for the Value. Both the key and the value are stored as strings.
  • Click SUBMIT to save the new data item.

gmSettingsTitleData_ub.png#asset:256

Setting Title Data by calling the server API in C#

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());
        }
    );
}

Internal Title Data

Similarly to UserData, 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.

Getting Title Data by calling the server API in C#

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());
        }
    );
}

Setting Title Data by calling the server API in C#

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());
        });
}

See Also

Using Publisher Data

Using Player Data

Using Cloud Script



Did you find this helpful?