Class ProjectSettingsInstance
- Namespace
- Godot
- Assembly
- GodotSharp.dll
Stores variables that can be accessed from everywhere. Use GetSetting(string, Variant), SetSetting(string, Variant) or HasSetting(string) to access them. Variables stored in project.godot
are also loaded into ProjectSettings, making this object very useful for reading custom game configuration options.
When naming a Project Settings property, use the full path to the setting including the category. For example, "application/config/name"
for the project name. Category and property names can be viewed in the Project Settings dialog.
Feature tags: Project settings can be overridden for specific platforms and configurations (debug, release, ...) using feature tags.
Overriding: Any project setting can be overridden by creating a file named override.cfg
in the project's root directory. This can also be used in exported projects by placing this file in the same directory as the project binary. Overriding will still take the base project settings' feature tags in account. Therefore, make sure to also override the setting with the desired feature tags if you want them to override base project settings on all platforms and configurations.
[GodotClassName("ProjectSettings")]
public class ProjectSettingsInstance : GodotObject, IDisposable
- Inheritance
-
ProjectSettingsInstance
- Implements
- Inherited Members
Methods
AddPropertyInfo(Dictionary)
Adds a custom property info to a property. The dictionary must contain:
- "name"
: string (the property's name)
- "type"
: int (see Variant.Type)
- optionally "hint"
: int (see PropertyHint) and "hint_string"
: string
Example:
ProjectSettings.Singleton.Set("category/property_name", 0);
var propertyInfo = new Godot.Collections.Dictionary
{
{"name", "category/propertyName"},
{"type", (int)Variant.Type.Int},
{"hint", (int)PropertyHint.Enum},
{"hint_string", "one,two,three"},
};
ProjectSettings.AddPropertyInfo(propertyInfo);
public void AddPropertyInfo(Dictionary hint)
Parameters
hint
Dictionary
Clear(string)
Clears the whole configuration (not recommended, may break things).
public void Clear(string name)
Parameters
name
string
GetGlobalClassList()
Returns an Array of registered global classes. Each global class is represented as a Dictionary that contains the following entries:
- base
is a name of the base class;
- class
is a name of the registered global class;
- icon
is a path to a custom icon of the global class, if it has any;
- language
is a name of a programming language in which the global class is written;
- path
is a path to a file containing the global class.
Note: Both the script and the icon paths are local to the project filesystem, i.e. they start with res://
.
public Array<Dictionary> GetGlobalClassList()
Returns
GetOrder(string)
Returns the order of a configuration value (influences when saved to the config file).
public int GetOrder(string name)
Parameters
name
string
Returns
GetSetting(string, Variant)
Returns the value of the setting identified by name
. If the setting doesn't exist and defaultValue
is specified, the value of defaultValue
is returned. Otherwise, null
is returned.
Example:
GD.Print(ProjectSettings.GetSetting("application/config/name"));
GD.Print(ProjectSettings.GetSetting("application/config/custom_description", "No description specified."));
Note: This method doesn't take potential feature overrides into account automatically. Use GetSettingWithOverride(StringName) to handle seamlessly.
public Variant GetSetting(string name, Variant defaultValue = default)
Parameters
Returns
GetSettingWithOverride(StringName)
Similar to GetSetting(string, Variant), but applies feature tag overrides if any exists and is valid.
Example:
If the following setting override exists "application/config/name.windows", and the following code is executed:
GD.Print(ProjectSettings.GetSettingWithOverride("application/config/name"));
Then the overridden setting will be returned instead if the project is running on the Windows operating system.
public Variant GetSettingWithOverride(StringName name)
Parameters
name
StringName
Returns
GlobalizePath(string)
Returns the absolute, native OS path corresponding to the localized path
(starting with res://
or user://
). The returned path will vary depending on the operating system and user preferences. See File paths in Godot projects to see what those paths convert to. See also LocalizePath(string).
Note:
GlobalizePath(string) with res://
will not work in an exported project. Instead, prepend the executable's base directory to the path when running from an exported project:
var path = ""
if OS.has_feature("editor"):
# Running from an editor binary.
# `path` will contain the absolute path to `hello.txt` located in the project root.
path = ProjectSettings.globalize_path("res://hello.txt")
else:
# Running from an exported project.
# `path` will contain the absolute path to `hello.txt` next to the executable.
# This is *not* identical to using `ProjectSettings.globalize_path()` with a `res://` path,
# but is close enough in spirit.
path = OS.get_executable_path().get_base_dir().path_join("hello.txt")
public string GlobalizePath(string path)
Parameters
path
string
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
HasSetting(string)
Returns true
if a configuration value is present.
public bool HasSetting(string name)
Parameters
name
string
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
LoadResourcePack(string, bool, int)
Loads the contents of the .pck or .zip file specified by pack
into the resource filesystem (res://
). Returns true
on success.
Note: If a file from pack
shares the same path as a file already in the resource filesystem, any attempts to load that file will use the file from pack
unless replaceFiles
is set to false
.
Note: The optional offset
parameter can be used to specify the offset in bytes to the start of the resource pack. This is only supported for .pck files.
public bool LoadResourcePack(string pack, bool replaceFiles = true, int offset = 0)
Parameters
Returns
LocalizePath(string)
Returns the localized path (starting with res://
) corresponding to the absolute, native OS path
. See also GlobalizePath(string).
public string LocalizePath(string path)
Parameters
path
string
Returns
Save()
Saves the configuration to the project.godot
file.
Note: This method is intended to be used by editor plugins, as modified ProjectSettings can't be loaded back in the running app. If you want to change project settings in exported projects, use SaveCustom(string) to save override.cfg
file.
public Error Save()
Returns
SaveCustom(string)
Saves the configuration to a custom file. The file extension must be .godot
(to save in text-based ConfigFile format) or .binary
(to save in binary format). You can also save override.cfg
file, which is also text, but can be used in exported projects unlike other formats.
public Error SaveCustom(string file)
Parameters
file
string
Returns
SetAsBasic(string, bool)
Defines if the specified setting is considered basic or advanced. Basic settings will always be shown in the project settings. Advanced settings will only be shown if the user enables the "Advanced Settings" option.
public void SetAsBasic(string name, bool basic)
Parameters
SetAsInternal(string, bool)
Defines if the specified setting is considered internal. An internal setting won't show up in the Project Settings dialog. This is mostly useful for addons that need to store their own internal settings without exposing them directly to the user.
public void SetAsInternal(string name, bool @internal)
Parameters
SetInitialValue(string, Variant)
Sets the specified setting's initial value. This is the value the setting reverts to.
public void SetInitialValue(string name, Variant value)
Parameters
SetOrder(string, int)
Sets the order of a configuration value (influences when saved to the config file).
public void SetOrder(string name, int position)
Parameters
SetRestartIfChanged(string, bool)
Sets whether a setting requires restarting the editor to properly take effect.
Note: This is just a hint to display to the user that the editor must be restarted for changes to take effect. Enabling SetRestartIfChanged(string, bool) does not delay the setting being set when changed.
public void SetRestartIfChanged(string name, bool restart)
Parameters
SetSetting(string, Variant)
Sets the value of a setting.
Example:
ProjectSettings.SetSetting("application/config/name", "Example");
This can also be used to erase custom project settings. To do this change the setting value to null
.
public void SetSetting(string name, Variant value)
Parameters
Events
SettingsChanged
Emitted when any setting is changed, up to once per process frame.
public event Action SettingsChanged