docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class FileSettingsRepository

    Represents a settings repository that stores data serialized to a JSON file.

    Inheritance
    object
    FileSettingsRepository
    PackageSettingsRepository
    ProjectUserSettings
    Implements
    ISettingsRepository
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: UnityEditor.SettingsManagement
    Assembly: Unity.Settings.Editor.dll
    Syntax
    [Serializable]
    public class FileSettingsRepository : ISettingsRepository

    Constructors

    FileSettingsRepository(string)

    Initializes and returns an instance of the FileSettingsRepository with the serialized data location set to the specified path.

    Declaration
    public FileSettingsRepository(string path)
    Parameters
    Type Name Description
    string path

    The project-relative path to save settings to.

    Fields

    k_PackageSettingsDirectory

    Location of where the package settings are saved under the ProjectSettings directory.

    Declaration
    protected const string k_PackageSettingsDirectory = "ProjectSettings/Packages"
    Field Value
    Type Description
    string

    k_UserProjectSettingsDirectory

    Location of where the package settings are saved under the UserSettings directory.

    Declaration
    protected const string k_UserProjectSettingsDirectory = "UserSettings/Packages"
    Field Value
    Type Description
    string

    Properties

    name

    Sets the name of file containing the serialized settings data.

    Declaration
    public string name { get; }
    Property Value
    Type Description
    string

    The bare filename of the settings file.

    path

    Gets the full path to the file containing the serialized settings data.

    Declaration
    public string path { get; }
    Property Value
    Type Description
    string

    The location stored for this repository.

    See Also
    path

    scope

    Sets the SettingsScope this repository applies to.

    Declaration
    public virtual SettingsScope scope { get; }
    Property Value
    Type Description
    SettingsScope

    Project, meaning that this setting applies to project settings (the default); or User, meaning that this setting applies to user preferences.

    Remarks

    By default, this repository implementation is relevant to the Project scope, but any implementations that override this method can choose to store this serialized data at a user scope instead.

    See Also
    scope

    Methods

    ContainsKey<T>(string)

    Determines whether this repository contains a settings entry that matches the specified key and is of type T.

    Declaration
    public bool ContainsKey<T>(string key)
    Parameters
    Type Name Description
    string key

    The key used to identify the settings entry.

    Returns
    Type Description
    bool

    True if a match is found for both key and type; false if no entry is found.

    Type Parameters
    Name Description
    T

    The type of value that this key points to.

    See Also
    ContainsKey<T>(string)

    Get<T>(string, T)

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

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

    The key used to identify the settings entry.

    T fallback

    Specify the value of type T to return if the entry can't be found.

    Returns
    Type Description
    T

    The settings value if a match is found; otherwise, it returns the default (fallback) value.

    Type Parameters
    Name Description
    T

    The type of value that this key points to.

    See Also
    Get<T>(string, T)

    Remove<T>(string)

    Removes a key-value pair from the settings repository. This method identifies the settings entry to remove by matching the specified key for a value of type T.

    Declaration
    public void Remove<T>(string key)
    Parameters
    Type Name Description
    string key

    The key used to identify the settings entry.

    Type Parameters
    Name Description
    T

    The type of value that this key points to.

    See Also
    Remove<T>(string)

    Save()

    Saves all settings to their serialized state.

    Declaration
    public void Save()
    See Also
    Save()

    Set<T>(string, T)

    Sets a value for a settings entry with a matching key and type T.

    Declaration
    public void Set<T>(string key, T value)
    Parameters
    Type Name Description
    string key

    The key used to identify the settings entry.

    T value

    The value to set. This value must be serializable.

    Type Parameters
    Name Description
    T

    The type of value that this key points to.

    See Also
    Set<T>(string, T)

    TryLoadSavedJson(out string)

    Loads the JSON file that stores the values for this settings object.

    Declaration
    public bool TryLoadSavedJson(out string json)
    Parameters
    Type Name Description
    string json

    The full path to the JSON file to load.

    Returns
    Type Description
    bool

    True if the file exists; false if it doesn't.

    Implements

    ISettingsRepository
    In This Article
    Back to top
    Copyright © 2026 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)