From 55c139f9f575d039601a29f51622897a148942cf Mon Sep 17 00:00:00 2001 From: kobewi Date: Mon, 2 Jun 2025 21:58:49 +0200 Subject: [PATCH] Clarify set_initial_value() --- doc/classes/ProjectSettings.xml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index fde926da72..3edc8a2761 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -205,7 +205,20 @@ - Sets the specified setting's initial value. This is the value the setting reverts to. + Sets the specified setting's initial value. This is the value the setting reverts to. The setting should already exist before calling this method. Note that project settings equal to their default value are not saved, so your code needs to account for that. + [codeblock] + extends EditorPlugin + + const SETTING_NAME = "addons/my_setting" + const SETTING_DEFAULT = 10.0 + + func _enter_tree(): + if not ProjectSettings.has_setting(SETTING_NAME): + ProjectSettings.set_setting(SETTING_NAME, SETTING_DEFAULT) + + ProjectSettings.set_initial_value(SETTING_NAME, SETTING_DEFAULT) + [/codeblock] + If you have a project setting defined by an [EditorPlugin], but want to use it in a running project, you will need a similar code at runtime.