How to mark ProjectSettings as dirty

Godot Version

Godot 4

Question

I have an EditorPlugin with a control that modifies a custom project setting. Sometimes lots of modifications are done in a short time period, so I’d like to mark the ProjectSettings as dirty rather than saving after every change to speed things up. How do I do this?

I looked at the source code for ProjectSettingsEditor and found that it simply uses a 1.5 second timer to delay saving. This way a number of settings changes can be queued up and will only be saved once. This can be done in GDScript as follows:

var save_timer: Timer

func _init() -> void:
	save_timer = Timer.new()
	save_timer.wait_time = 1.5 # Matching ProjectSettingsEditor behaviour
	save_timer.timeout.connect(ProjectSettings.save)
	save_timer.one_shot = true
	add_child(save_timer)

func queue_save() -> void:
	save_timer.start()

Then simply call queue_save() to save the ProjectSettings. Every time the timer is started, it will restart the countdown. This way the save will only happen after 1.5 seconds of no calls to queue_save().

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.