docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class DataStore

    DataStore stores string, float, and integer values that can be easily saved and loaded using the ISavingSystem.

    Inheritance
    object
    DataStore
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.PlatformToolkit
    Assembly: Unity.PlatformToolkit.dll
    Syntax
    public class DataStore
    Remarks

    Changes to DataStore objects are local and are only saved after calling Save(ISavingSystem, string).

    Methods

    Create()

    Creates an empty DataStore object.

    Declaration
    public static DataStore Create()
    Returns
    Type Description
    DataStore

    New DataStore.

    DeleteAll()

    Deletes all keys and values from the DataStore save.

    Declaration
    public void DeleteAll()
    Remarks

    Does not delete the image.

    DeleteKey(string)

    Deletes the specified key and value.

    Declaration
    public void DeleteKey(string key)
    Parameters
    Type Name Description
    string key

    The key to delete.

    GetFloat(string)

    Retrieves a float value.

    Declaration
    public float GetFloat(string key)
    Parameters
    Type Name Description
    string key

    The key of the value to retrieve.

    Returns
    Type Description
    float

    The float value associated with the specified key. If it doesn't exist the default value will be returned.

    GetFloat(string, float)

    Retrieves a float value.

    Declaration
    public float GetFloat(string key, float defaultValue)
    Parameters
    Type Name Description
    string key

    The key of the value to retrieve.

    float defaultValue

    The default value to return if the key doesn't exist.

    Returns
    Type Description
    float

    The float value associated with the specified key. If it doesn't exist the default value will be returned.

    GetInt(string)

    Retrieves an int value.

    Declaration
    public int GetInt(string key)
    Parameters
    Type Name Description
    string key

    The key of the value to retrieve.

    Returns
    Type Description
    int

    The integer value associated with the specified key. If it doesn't exist the default value will be returned.

    GetInt(string, int)

    Retrieves an int value.

    Declaration
    public int GetInt(string key, int defaultValue)
    Parameters
    Type Name Description
    string key

    The key of the value to retrieve.

    int defaultValue

    The default value to return if the key doesn't exist.

    Returns
    Type Description
    int

    The integer value associated with the specified key. If it doesn't exist the default value will be returned.

    GetString(string)

    Retrieves a string value.

    Declaration
    public string GetString(string key)
    Parameters
    Type Name Description
    string key

    The key of the value to retrieve.

    Returns
    Type Description
    string

    The string value associated with the specified key. If it doesn't exist the default value will be returned.

    GetString(string, string)

    Retrieves a string value.

    Declaration
    public string GetString(string key, string defaultValue)
    Parameters
    Type Name Description
    string key

    The key of the value to retrieve.

    string defaultValue

    The default value to return if the key doesn't exist.

    Returns
    Type Description
    string

    The string value associated with the specified key. If it doesn't exist the default value will be returned.

    HasKey(string)

    Checks if the specified key exists in the DataStore save.

    Declaration
    public bool HasKey(string key)
    Parameters
    Type Name Description
    string key

    The key to check.

    Returns
    Type Description
    bool

    True if the key exists, otherwise false.

    Load(ISavingSystem, string, bool)

    Loads DataStore object from an existing ISavingSystem save.

    Declaration
    public static Task<DataStore> Load(ISavingSystem savingSystem, string saveName, bool createIfNotFound = true)
    Parameters
    Type Name Description
    ISavingSystem savingSystem

    The saving system to use.

    string saveName

    The name of the save.

    bool createIfNotFound

    If true, a new DataStore will be created if the save doesn't already exist. If false, an exception will be thrown if the save is not found.

    Returns
    Type Description
    Task<DataStore>

    Task containing the DataStore save.

    Exceptions
    Type Condition
    ArgumentNullException

    ISavingSystem is null.

    InvalidAccountException

    IAccount linked to the ISavingSystem is signed out.

    InvalidSystemException

    ISavingSystem is invalid.

    InvalidOperationException

    Save is already open.

    ArgumentException

    The given saving system or save name is null. The save name might contain invalid characters, is too long, or is empty.

    Save(ISavingSystem, string)

    Saves the DataStore object into an ISavingSystem save.

    Declaration
    public Task Save(ISavingSystem savingSystem, string saveName)
    Parameters
    Type Name Description
    ISavingSystem savingSystem

    The saving system to use.

    string saveName

    The name of the save.

    Returns
    Type Description
    Task

    Task that completes when the save is saved.

    Exceptions
    Type Condition
    ArgumentException

    The given saving system or save name is null. The save name might contain invalid characters, is too long, or is empty.

    NotEnoughSpaceException

    There's not enough space to write the data. This can mean that the system is out of memory, but other limits can also be imposed by platforms. For example, limits on how much storage is allocated for each account or how large a single commit can be.

    IOException

    There was an error writing or committing the data.

    InvalidAccountException

    IAccount linked to the ISavingSystem is signed out.

    InvalidSystemException

    ISavingSystem is invalid.

    SetFloat(string, float)

    Sets a float value for the given key.

    Declaration
    public void SetFloat(string key, float value)
    Parameters
    Type Name Description
    string key

    The key of the value to set.

    float value

    The float value to set.

    SetInt(string, int)

    Sets an integer value for the given key.

    Declaration
    public void SetInt(string key, int value)
    Parameters
    Type Name Description
    string key

    The key of the value to set.

    int value

    The integer value to set.

    SetString(string, string)

    Sets a string value for a given key.

    Declaration
    public void SetString(string key, string value)
    Parameters
    Type Name Description
    string key

    The key of the value to set.

    string value

    The string value to set.

    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)