I created this topic so I could ask you a question, how can I change the configuration of a Godot project through code. What happens is that I want to create a configuration menu for my project, which would be to change the resolution to give an example.
It sounds simple and it really is, but it turns out that most of the information is very old and is no longer compatible with Godot 4, since the majority would be for version 3.
I have tried using plugins like Godot Game Settings to make the task easier, but it turned out that it greatly reduced performance and caused many errors in its execution. Although this can be caused by many reasons not linked to the plugins.
You can use
ProjectSettingsto read and write project settings. This is particularly useful for editor plugins.There are various points when Godot reads the project settings. However, once it have read it, changing it has no effect. For example, if you game already started, changing the resolution in project settings is of no use.
For the resolution, you probably want to manipulate the main
Window, which is the root of the scene tree (get_tree().root).You can use
get_tree().root.modeto change between windowed and fullscreen. And, of course, the size of the window isget_tree().root.size. Also see thecontent_scale_*properties which control how theWindowwill scale and stretch its contents.You might also be interested in
DisplayServer.