diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index e8c885162b2..8ea92f66920 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -283,6 +283,7 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) { for (int i = 0; i < custom_feature_array.size(); i++) { custom_features.insert(custom_feature_array[i]); } + _queue_changed(); return true; } @@ -324,6 +325,7 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) { } } + _queue_changed(); return true; } @@ -424,6 +426,22 @@ void ProjectSettings::_get_property_list(List *p_list) const { } } +void ProjectSettings::_queue_changed() { + if (is_changed || !MessageQueue::get_singleton() || MessageQueue::get_singleton()->get_max_buffer_usage() == 0) { + return; + } + is_changed = true; + callable_mp(this, &ProjectSettings::_emit_changed).call_deferred(); +} + +void ProjectSettings::_emit_changed() { + if (!is_changed) { + return; + } + is_changed = false; + emit_signal("settings_changed"); +} + bool ProjectSettings::_load_resource_pack(const String &p_pack, bool p_replace_files, int p_offset) { if (PackedData::get_singleton()->is_disabled()) { return false; @@ -1225,6 +1243,8 @@ void ProjectSettings::_bind_methods() { ClassDB::bind_method(D_METHOD("load_resource_pack", "pack", "replace_files", "offset"), &ProjectSettings::_load_resource_pack, DEFVAL(true), DEFVAL(0)); ClassDB::bind_method(D_METHOD("save_custom", "file"), &ProjectSettings::_save_custom_bnd); + + ADD_SIGNAL(MethodInfo("settings_changed")); } void ProjectSettings::_add_builtin_input_map() { diff --git a/core/config/project_settings.h b/core/config/project_settings.h index a1f52fa1e0e..dba4aa6822d 100644 --- a/core/config/project_settings.h +++ b/core/config/project_settings.h @@ -45,6 +45,8 @@ class ProjectSettings : public Object { _THREAD_SAFE_CLASS_ friend class TestProjectSettingsInternalsAccessor; + bool is_changed = false; + public: typedef HashMap CustomMap; static const String PROJECT_DATA_DIR_NAME_SUFFIX; @@ -115,6 +117,9 @@ protected: bool _property_can_revert(const StringName &p_name) const; bool _property_get_revert(const StringName &p_name, Variant &r_property) const; + void _queue_changed(); + void _emit_changed(); + static ProjectSettings *singleton; Error _load_settings_text(const String &p_path); diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 40a475851df..52419882b09 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -2710,4 +2710,11 @@ If [code]true[/code], Godot will compile shaders required for XR. + + + + Emitted when any setting is changed, up to once per process frame. + + +