2.2 KiB
2.2 KiB
Adding Custom Options
This page covers adding new buttons, sliders, or editable text fields to the options menus that automatically persist between sessions.
To the Menu
Custom options can be added to a menu without any code.
- Add an
option_control.tscnnode as a child to a container in a scene.slider_option_control.tscnortoggle_option_control.tscncan be used if those types match requirements. In that case, skip step 6.list_option_control.tscnandvector_2_list_option_control.tscnare also available, but more complicated. See theScreenResolutionexample.
- Select the
OptionControlnode just added, to edit it in the inspector. - Add an
Option Name. This prefills theKeystring. - Select an
Option Section. This prefills theSectionstring. - Add any kind of
Button,Slider,LineEdit, orTextEditto theOptionControlnode. - Save the scene.
To the Game
For options to have any effect outside of the menus, they will need to be referenced by their key and section from the PlayerConfig class.
PlayerConfig.get_config(key, section)
For example, here is how to get the player's desired input sensitivity for controlling a player camera.
var mouse_sensitivity : float = PlayerConfig.get_config(AppSettings.INPUT_SECTION, "MouseSensitivity", 1.0)
var joypad_sensitivity : float = PlayerConfig.get_config(AppSettings.INPUT_SECTION, "JoypadSensitivity", 1.0)
Validation
Validate the values being stored in your local player_config.cfg file.
- Refer to Accessing Persistent User Data User to find Godot user data on your machine.
- Find the directory that matches your project's name.
- Open
player_config.cfg(should be in the top directory of the project). - Find the section by the section name in brackets, and the key name followed by an equals.
For example, here is how the player's desired input sensitivity could appear in the config file.
[InputSettings]
MouseSensitivity=1.05
JoypadSensitivity=0.95
Note
Some settings may not appear until they have been customized.