How can I change display/window/stretch/scale in a script?

Godot Version

Godot 4.2


In Project Settings → View → Window we have a stretch scale. I want to change the same parameter in a script. How can I?

What I do changes the value, but it doesn’t change anything in the scene :
func scale_to_resolution(resolution):
ProjectSettings.set_setting(“display/window/stretch/scale”, resolution)

I believe you’re setting the property correctly. However, it looks like this property is only used once on startup and doesn’t update on real-time changed in-game.