- Edited
I'm making a game that normally runs at a fixed resolution with viewport scaling so everything is pixel perfect, and I'm trying to add an option to the game that allows it to run with canvas item scaling instead, so the game runs at the monitor's resolution instead of its own fixed res. For whatever reason, though, simply setting the ProjectSetting in code doesn't seem to do anything. both set_setting() and set_initial_value() don't do anything, and the game just uses whatever I manually set in the editor project settings. Anybody know a solution or workaround?
Here's how I save and load the setting:
func _ready():
visible = false
await get_tree().create_timer(0).timeout #wait for the configfile to load
load_settings()
func save_settings():
save_value("video", "resolution",$menu/tabs/video/resolution.button_pressed)
if saved_settings.get_value("video","resolution"):
ProjectSettings.set_setting("display/window/stretch/mode","canvas_items")
else:
ProjectSettings.set_setting("display/window/stretch/mode","viewport")
func load_settings():
file_loaded = false
if FileAccess.file_exists(save_path): #check if a config file exists
print("config file exists, loading...")
saved_settings.load(save_path)
print("file loaded, loading settings")
else: #if no save file exists, create a new one
print("no config file found, creating a new one...")
save_settings()
print("new config file created")
$menu/tabs/video/resolution.button_pressed = saved_settings.get_value("video","resolution")
if saved_settings.get_value("video","resolution"):
ProjectSettings.set_setting("display/window/stretch/mode","canvas_items")
print("native resolution enabled")
else:
ProjectSettings.set_setting("display/window/stretch/mode","viewport")
print("native resolution disabled")