+3 votes

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?

in Engine by (58 points)

2 Answers

+1 vote
Best answer

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].

by (5,206 points)
selected by

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. Testwidth and testheight seem to serve that purpose instead.

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

+4 votes

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

by (22 points)

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.