How do you change project settings at runtime and have them persist?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jeff
:warning: Old Version Published before Godot 3 was released.

Right now I’m creating the Settings panel for my game, and I figured that the cleanest way to go about this is to persist the changes to the actual project settings themselves.

For example, for the resolution setting, after the user picks the resolution I run the following:

OS.set_window_size(resolution) #it appears setting the property doesn't actually change the resolution, so I have to call this as well

Globals.set("display/height", resolution.y)
Globals.set("display/width", resolution.x)

After calling the set function, the property does change to the new value. However, after exiting the game, the property is reverted back to the original value. Am I simply not supposed to adjust the Project Settings dynamically, or is there something I’m missing?

:bust_in_silhouette: Reply From: avencherus

I don’t know how well it will work outside of tool script, but if you want to save Globals you do the following:

Globals.set_persisting("display/width", true)
Globals.set("display/width", x)
Globals.save()

If that doesn’t work you probably have to read and parse the engine.cfg file, and change the appropriate setting under the [Category].

Thank you, this is the correct answer for editing the project settings. Not sure why I couldn’t find the save() call in previous answers. Additionally, for my purposes, I forgot that the width and height specified is separate from the resized resolution. Test_width and test_height seem to serve that purpose instead.

jeff | 2017-12-20 22:15

No problem Jeff. It had me vexed once too. X)

avencherus | 2017-12-21 04:03

:bust_in_silhouette: Reply From: FeralBytes0

I think this recently changed. So for those looking for the answer I found it to be:

ProjectSettings.set_setting("application/config/name", "Example")

ProjectSettings from the docs for Godot 3.2.3

“Most project settings are only read when the project starts. This means changing them at run-time won’t apply any visible changes.”

luislodosm | 2021-05-21 10:54