ProjectSettings

package
v0.0.0-...-0d6c339 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Stores variables that can be accessed from everywhere. Use GetSetting, SetSetting or HasSetting to access them. Variables stored in project.godot are also loaded into graphics.gd/classdb/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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPropertyInfo

func AddPropertyInfo(hint Object.PropertyInfo)

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

Note: Setting "usage" for the property is not supported. Use SetAsBasic, SetRestartIfChanged, and SetAsInternal to modify usage flags.

func Advanced

func Advanced() class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

func Clear

func Clear(name string)

Clears the whole configuration (not recommended, may break things).

func GetOrder

func GetOrder(name string) int

Returns the order of a configuration value (influences when saved to the config file).

func GetSetting

func GetSetting(name string, default_value any) any

Returns the value of the setting identified by 'name'. If the setting doesn't exist and 'default_value' is specified, the value of 'default_value' is returned. Otherwise, null is returned.

Note: This method doesn't take potential feature overrides into account automatically. Use GetSettingWithOverride to handle seamlessly.

See also HasSetting to check whether a setting exists.

func GetSettingOptions

func GetSettingOptions(name string, default_value any) any

Returns the value of the setting identified by 'name'. If the setting doesn't exist and 'default_value' is specified, the value of 'default_value' is returned. Otherwise, null is returned.

Note: This method doesn't take potential feature overrides into account automatically. Use GetSettingWithOverride to handle seamlessly.

See also HasSetting to check whether a setting exists.

func GetSettingWithOverride

func GetSettingWithOverride(name string) any

Similar to GetSetting, but applies feature tag overrides if any exists and is valid.

Example: If the setting override "application/config/name.windows" exists, and the following code is executed on a Windows operating system, the overridden setting is printed instead:

func GetSettingWithOverrideAndCustomFeatures

func GetSettingWithOverrideAndCustomFeatures(name string, features []string) any

Similar to GetSettingWithOverride, but applies feature tag overrides instead of current OS features.

func GlobalizePath

func GlobalizePath(path string) 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.

Note: GlobalizePath 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:

func HasSetting

func HasSetting(name string) bool

Returns true if a configuration value is present.

Note: In order to be be detected, custom settings have to be either defined with SetSetting, or exist in the project.godot file. This is especially relevant when using SetInitialValue.

func LoadResourcePack

func LoadResourcePack(pack string, offset int) bool

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 'replace_files' 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.

Note: graphics.gd/classdb/DirAccess will not show changes made to the contents of res:// after calling this function.

func LoadResourcePackOptions

func LoadResourcePackOptions(pack string, replace_files bool, offset int) bool

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 'replace_files' 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.

Note: graphics.gd/classdb/DirAccess will not show changes made to the contents of res:// after calling this function.

func LocalizePath

func LocalizePath(path string) string

Returns the localized path (starting with res://) corresponding to the absolute, native OS 'path'. See also GlobalizePath.

func OnSettingsChanged

func OnSettingsChanged(cb func(), flags ...Signal.Flags)

func Save

func Save() error

Saves the configuration to the project.godot file.

Note: This method is intended to be used by editor plugins, as modified graphics.gd/classdb/ProjectSettings can't be loaded back in the running app. If you want to change project settings in exported projects, use SaveCustom to save override.cfg file.

func SaveCustom

func SaveCustom(file string) error

Saves the configuration to a custom file. The file extension must be .godot (to save in text-based graphics.gd/classdb/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.

func SetAsBasic

func SetAsBasic(name string, basic 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.

func SetAsInternal

func SetAsInternal(name string, internal_ 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.

func SetInitialValue

func SetInitialValue(name string, value any)

Sets the specified setting's initial value. This is the value the setting reverts to. The setting should already exist before calling this method. Note that project settings equal to their default value are not saved, so your code needs to account for that.

If you have a project setting defined by an graphics.gd/classdb/EditorPlugin, but want to use it in a running project, you will need a similar code at runtime.

func SetOrder

func SetOrder(name string, position int)

Sets the order of a configuration value (influences when saved to the config file).

func SetRestartIfChanged

func SetRestartIfChanged(name string, restart 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 does not delay the setting being set when changed.

func SetSetting

func SetSetting(name string, value any)

Sets the value of a setting.

This can also be used to erase custom project settings. To do this change the setting value to null.

Types

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

type GlobalClass

type GlobalClass struct {
	Base     string `gd:"base"`
	Class    string `gd:"class"`
	Icon     string `gd:"icon"`
	Language string `gd:"language"`
	Path     string `gd:"path"`
}

func GetGlobalClassList

func GetGlobalClassList() []GlobalClass

Returns an slice of registered global classes. Each global class is represented as a data structure 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://.

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.ProjectSettings

Instance of the class with convieniently typed arguments and results.

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) ID

func (self Instance) ID() ID

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL