Skip to main content

Class Settings<T>

Base class for project/user settings. Use the SettingsAttribute to specify its usage, display path, and filename.

public abstract class Settings<T> : ScriptableObject where T : Settings<T>

Type Parameters​

NameTypeDescription
T

Inheritance​

Extension Methods​

Examples​

Example of a method to create a custom SettingsProvider:

[SettingsProvider]
public static SettingsProvider CreateMySettingsProvider()
{
var provider = new SettingsProvider("Project/Example/Settings", SettingsScope.Project)
{
activateHandler = (searchContext, rootElement) =>
{
var settings = new SerializedObject(instance);
// ... (Add custom UI elements and layout using UI Toolkit here)
rootElement.Bind(settings);
}
};
return provider;
}

Remarks​

Settings are stored in the Assets/Settings/ folder. The user settings folder Assets/Settings/Editor/User/ must be excluded from source control. User settings will be placed in a subdirectory named the same as the current project folder so that shallow cloning (symbolic links to the Assets/ folder) can be used when testing multiplayer games.

In order for the setting to appear in the Unity Project Settings window, you must also create a corresponding SettingsProvider. You can use the built-in base class ScriptableObjectSettingsProvider by calling Settings{``0}) or create a custom SettingsProvider clas.

Additionally, the setting needs to be preloaded to ensures that the settings asset is referenceable after build. Typically, this is done by adding it manually to the project setting's preload list, or by implementing a custom class derived from SettingsBuildHelper.

See: Unity Custom Settings

Properties​

attribute​

The derived type's SettingsAttribute attribute.

public static SettingsAttribute attribute { get; }

Property Value​

SettingsAttribute

instance​

Gets the singleton instance of the settings.

public static T instance { get; }

Property Value​

T

Methods​

Initialize()​

Loads or creates the settings instance and stores it in _instance.

protected static T Initialize()

Returns​

T — The settings instance of type T.

OnValidate()​

Called to validate settings changes.

protected virtual void OnValidate()

Set<S>(ref S, S)​

Sets the specified setting to the desired value and marks the settings so that it will be saved.

protected void Set<S>(ref S setting, S value)

Parameters​

NameTypeDescription
settingSThe setting to modify.
valueSThe new value for the setting.

Type Parameters​

NameTypeDescription
SThe type of the setting.

SetDirty()​

Marks the settings as dirty so that they will be saved.

protected void SetDirty()