User Preferences
Unlike the Save/Load System , which handles game data related to the game loop, User Preferences (UserPrefs) are used to store global settings unrelated to gameplay. These are ideal for saving user settings such as music volume, sound effects volume, selected language, or any other preferences you want to include.
In the template, saving and loading user preferences is managed by the user_prefs.gd
script. Preferences are automatically loaded when opening the settings_menu.tscn
scene, handled by settings_menu.gd
, and automatically saved when exiting the scene.
Available User Preferences
In the SettingsMenu
scene, the following preferences are available by default:
- Music Volume
- SFX Volume
- Language
You can extend this system by adding new preferences in your game and managing their values as demonstrated in settings_menu.gd
.
How to Save and Load User Preferences
-
Load or Create User Preferences
First, create or load aUserPrefs
instance using:user_prefs = UserPrefs.load_or_create()
-
Modify Preferences
When a setting is changed, update the corresponding value inuser_prefs
:user_prefs.language = lang
-
Save the Preferences
Finally, save the preferences to a file using:user_prefs.save()
Localization
To make your game accessible in different languages, Godot’s built-in localization system is used. You can find the full documentation here .
Setting Up Translations
Localization is handled via a CSV translation file, where each column corresponds to a language. You can refer to the translations.csv
file included in the template as an example.
Make sure to import your CSV file as CSV Translation in Godot. It’s recommended to set the delimiter
to Semicolon (;), especially if you plan to use the same file for dialogue translations.
![import translation csv](/_astro/_1_import_translation_csv.CRNTNv20_ZTTHkX.webp)
For Control nodes, translation is handled automatically as long as auto_translate_mode
is not set to Disabled.
![Auto translate mode](/_astro/_2_auto_translate_mode.Ex12oOpR_Zuz9Dl.webp)
For dialogues managed by the Dialogue System , refer to the Godot Dialogue Manager documentation on translations .
Adding or Removing Languages
To modify the available languages, update the LANGUAGES
array in Const.gd
. Languages listed here will appear in the Language dropdown in the SettingsMenu
scene.
Ensure that each language in the LANGUAGES
array has a corresponding column
in the CSV Translation file.