docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class Settings

    Settings manages a collection of ISettingsRepository.

    Inheritance
    object
    Settings
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: UnityEditor.SettingsManagement
    Assembly: Unity.Settings.Editor.dll
    Syntax
    public sealed class Settings

    Constructors

    Settings(IEnumerable<ISettingsRepository>)

    Create a new Settings instance with a collection of ISettingsRepository.

    Declaration
    public Settings(IEnumerable<ISettingsRepository> repositories)
    Parameters
    Type Name Description
    IEnumerable<ISettingsRepository> repositories

    Settings(string, string)

    Create a new Settings instance with a UserSettingsRepository and PackageSettingsRepository.

    Declaration
    public Settings(string package, string settingsFileName = "Settings")
    Parameters
    Type Name Description
    string package

    The package name. Ex, com.unity.my-package.

    string settingsFileName

    The name of the settings file. Defaults to "Settings."

    Methods

    ContainsKey<T>(string, string, SettingsScope)

    Does the repository contain a setting with key and type.

    Declaration
    public bool ContainsKey<T>(string key, string repositoryName, SettingsScope scope = SettingsScope.Project)
    Parameters
    Type Name Description
    string key

    The settings key.

    string repositoryName

    The repository name to match.

    SettingsScope scope

    Which scope should be searched for matching key.

    Returns
    Type Description
    bool

    True if a setting matching both key and type is found, false if no entry is found.

    Type Parameters
    Name Description
    T

    The type of value to search for.

    ContainsKey<T>(string, SettingsScope)

    Does the repository contain a setting with key and type.

    Declaration
    public bool ContainsKey<T>(string key, SettingsScope scope = SettingsScope.Project)
    Parameters
    Type Name Description
    string key

    The settings key.

    SettingsScope scope

    Which scope should be searched for matching key.

    Returns
    Type Description
    bool

    True if a setting matching both key and type is found, false if no entry is found.

    Type Parameters
    Name Description
    T

    The type of value to search for.

    DeleteKey<T>(string, string, SettingsScope)

    Remove a key value pair from a settings repository.

    Declaration
    public void DeleteKey<T>(string key, string repositoryName, SettingsScope scope = SettingsScope.Project)
    Parameters
    Type Name Description
    string key

    The key to remove.

    string repositoryName

    The repository name to match.

    SettingsScope scope

    Which scope should be searched for matching key.

    Type Parameters
    Name Description
    T

    The type that this key is pointing to.

    DeleteKey<T>(string, SettingsScope)

    Remove a key value pair from a settings repository.

    Declaration
    public void DeleteKey<T>(string key, SettingsScope scope = SettingsScope.Project)
    Parameters
    Type Name Description
    string key

    The key to remove.

    SettingsScope scope

    Which scope should be searched for matching key.

    Type Parameters
    Name Description
    T

    The type that this key is pointing to.

    GetRepository(SettingsScope)

    Find a settings repository that matches the requested scope.

    Declaration
    public ISettingsRepository GetRepository(SettingsScope scope)
    Parameters
    Type Name Description
    SettingsScope scope

    The scope of the settings repository to match.

    Returns
    Type Description
    ISettingsRepository

    An ISettingsRepository instance that is implementing the requested scope. May return null if no matching repository is found.

    GetRepository(SettingsScope, string)

    Find a settings repository that matches the requested scope and name.

    Declaration
    public ISettingsRepository GetRepository(SettingsScope scope, string name)
    Parameters
    Type Name Description
    SettingsScope scope

    The scope of the settings repository to match.

    string name

    The name of the ISettingsRepository to match.

    Returns
    Type Description
    ISettingsRepository

    An ISettingsRepository instance that is implementing the requested scope, and matches name. May return null if no matching repository is found.

    Get<T>(string, string, SettingsScope, T)

    Get a value with key of type T, or return the fallback value if no matching key is found.

    Declaration
    public T Get<T>(string key, string repositoryName, SettingsScope scope = SettingsScope.Project, T fallback = default)
    Parameters
    Type Name Description
    string key

    The settings key.

    string repositoryName

    The repository name to match.

    SettingsScope scope

    Which scope this settings should be retrieved from.

    T fallback

    If no key with a value of type T is found, this value is returned.

    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    Type of value to search for.

    Get<T>(string, SettingsScope, T)

    Get a value with key of type T, or return the fallback value if no matching key is found.

    Declaration
    public T Get<T>(string key, SettingsScope scope = SettingsScope.Project, T fallback = default)
    Parameters
    Type Name Description
    string key

    The settings key.

    SettingsScope scope

    Which scope this settings should be retrieved from.

    T fallback

    If no key with a value of type T is found, this value is returned.

    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    Type of value to search for.

    Save()

    Serialize the state of all settings repositories.

    Declaration
    public void Save()

    Set<T>(string, T, string, SettingsScope)

    Set a value for key of type T.

    Declaration
    public void Set<T>(string key, T value, string repositoryName, SettingsScope scope = SettingsScope.Project)
    Parameters
    Type Name Description
    string key

    The settings key.

    T value

    The value to set. Must be serializable.

    string repositoryName

    The repository name to match.

    SettingsScope scope

    Which scope this settings should be saved in.

    Type Parameters
    Name Description
    T

    Type of value.

    Set<T>(string, T, SettingsScope)

    Set a value for key of type T.

    Declaration
    public void Set<T>(string key, T value, SettingsScope scope = SettingsScope.Project)
    Parameters
    Type Name Description
    string key

    The settings key.

    T value

    The value to set. Must be serializable.

    SettingsScope scope

    Which scope this settings should be saved in.

    Type Parameters
    Name Description
    T

    Type of value.

    Events

    afterSettingsSaved

    Declaration
    public event Action afterSettingsSaved
    Event Type
    Type Description
    Action

    An event that is raised after an ISettingsRepository has serialized it's current state.

    beforeSettingsSaved

    Declaration
    public event Action beforeSettingsSaved
    Event Type
    Type Description
    Action

    An event that is raised prior to an ISettingsRepository serializing it's current state.

    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)