TikTok for Developers

Developer Docs

Last updated October 5, 2026

Data Storage

Choose key-value storage or object storage based on the data shape. Your game must manage data versions, migration, overwrites, and cleanup; uploading a new build does not automatically delete existing data.

TT.PlayerPrefs

Provides key-value storage for int, float, and string values. Call Save() after writing or deleting data to persist the changes.

SetInt

Signature

public void SetInt(string key, int value)

Parameters

Parameter

Type

Description

key

string

Storage key.

value

int

Integer to save.

Example

TT.PlayerPrefs.SetInt("level", 5);

GetInt

Signature

public int GetInt(string key, int defaultValue)

Return value

Returns the saved integer when the key exists; otherwise, returns defaultValue.

Example

int level = TT.PlayerPrefs.GetInt("level", 1);

SetFloat

Signature

public void SetFloat(string key, float value)

Example

TT.PlayerPrefs.SetFloat("music_volume", 0.8f);

GetFloat

Signature

public float GetFloat(string key, float defaultValue)

Return value

Returns the saved floating-point value when the key exists; otherwise, returns defaultValue.

Example

float volume = TT.PlayerPrefs.GetFloat("music_volume", 1.0f);

SetString

Signature

public void SetString(string key, string value)

Example

TT.PlayerPrefs.SetString("player_name", "Alex");

GetString

Signature

public string GetString(string key, string defaultValue)

Return value

Returns the saved string when the key exists; otherwise, returns defaultValue.

Example

string playerName = TT.PlayerPrefs.GetString("player_name", string.Empty);

HasKey

Checks whether a specified key exists.

Signature

public bool HasKey(string key)

Return value

Returns true when the key exists; otherwise, returns false.

Example

bool exists = TT.PlayerPrefs.HasKey("player_name");

DeleteKey

Deletes the specified key. Call Save() afterward to persist the change.

Signature

public void DeleteKey(string key)

Example

TT.PlayerPrefs.DeleteKey("player_name");
TT.PlayerPrefs.Save();

DeleteAll

Deletes all key-value data stored through TT.PlayerPrefs.

Signature

public void DeleteAll()

Example

TT.PlayerPrefs.DeleteAll();
TT.PlayerPrefs.Save();

DeleteAll removes all key-value data. Call it only in explicit flows such as resetting local data.

Save

Persists the current TT.PlayerPrefs changes.

Signature

public void Save()

Example

TT.PlayerPrefs.SetInt("level", 5);
TT.PlayerPrefs.Save();

TT.Save(serializableObject, saveName)

Saves a serializable object under a specified name.

Signature

public static bool Save<T>(T serializableObject, string saveName)

Parameters

Parameter

Type

Description

serializableObject

T

Serializable object to save.

saveName

string

Save name.

Return value

Returns true when the object is saved successfully; otherwise, returns false.

Example

bool saved = TT.Save(
    new PlayerSave { level = 5, coins = 120 },
    "player_save"
);

TT.LoadSaving(saveName)

Loads a saved object by name. The generic type must match the data structure used when the object was saved.

Signature

public static T LoadSaving<T>(string saveName)

Return value

Returns the deserialized object.

Example

PlayerSave save = TT.LoadSaving<PlayerSave>("player_save");

TT.DeleteSaving(saveName)

Deletes the object save with the specified name.

Signature

public static void DeleteSaving(string saveName)

Example

TT.DeleteSaving("player_save");

TT.ClearAllSavings()

Deletes all data saved through the object-storage APIs.

Signature

public static void ClearAllSavings()

Example

TT.ClearAllSavings();

ClearAllSavings deletes all object saves. Confirm that the game no longer needs the data before calling it.

TT.GetSavingDiskSize()

Reads the storage space currently used by object saves.

Signature

public static long GetSavingDiskSize()

Return value

Returns the number of bytes used by object saves.

Example

long bytes = TT.GetSavingDiskSize();
Debug.Log($"Saving size: {bytes} bytes");

Object type example

using System;

[Serializable]
public class PlayerSave
{
    public int level;
    public int coins;
}
TikTok for Developers