Saving class config

Hello. I have a class which is located in plugin module

UCLASS(Config=Game, DefaultConfig)
class UVRENDERPASSSETTINGS_API UUVRenderPassSettings : public UObject
{
  GENERATED_BODY()

public:
  /**
   * Enable or disable UV render pass.
   * When disabled, no UV rendering will occur and the render pass will be completely inactive.
   */
  UPROPERTY(EditAnywhere, Config, Category="Render Pass")
  bool bEnabled = false;

And plugin module registers settings for editor:

  if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
  {
    SettingsModule->RegisterSettings(
      "Project", "Plugins", "UVRenderPass",
      NSLOCTEXT("UVRenderPass", "SettingsName", "UV Render Pass"),
      NSLOCTEXT("UVRenderPass", "SettingsDescription", "Configure the UV Render Pass plugin."),
      GetMutableDefault<UUVRenderPassSettings>()
    );
  }

When i edit UVRenderPassSettings settings in editor it saves changes in DefaultGame.ini fine.

But if i remove DefaultConfig from class, changes are not saving anywhere.

I wanted to reach the next behaviour:

  1. I have a class with default settings defined in DefaultGame.ini
  2. If i change settings in editor it saves in Saved/Config/Windows/Game.ini

But it does not happen but was expected to be happen (as other classes works so)

I have tried to force SaveConfig() like so:

    auto Setting = SettingsModule->RegisterSettings(
      "Project", "Plugins", "UVRenderPass",
      NSLOCTEXT("UVRenderPass", "SettingsName", "UV Render Pass"),
      NSLOCTEXT("UVRenderPass", "SettingsDescription", "Configure the UV Render Pass plugin."),
      GetMutableDefault<UUVRenderPassSettings>()
    );

    Setting->OnModified().BindLambda([Setting]() -> bool
    {
        Setting->GetSettingsObject()->SaveConfig();
        return true;
    });

And it did not worked too. Game.ini was not saved in Saved/Config/Windows/Game.ini with overrided parameters.

Can you please check what am i doing wrong or missing.

Hi Slava,

Your C++ code is correct, and I believe it would work according to your expectations in versions up to UE 5.3. However, starting with UE 5.4, there was an important change in the persistence of settings between Editor sessions, which unfortunately does not seem to have been well documented. But just to get this out of the way, you don’t need to call SaveConfig() manually for settings that are being changed by the user through the Project Settings pages.

Now, let me clarify the distinction between having or not the “DefaultConfig” tag on your settings class:

  • When a class has the “DefaultConfig” tag, making changes to its properties through the “Project Settings” dialog causes the corresponding “<PROJECT>/Config/Default<CATEGORY>.ini” file to be immediately updated. This means its properties are “default-only”, there are no “per-session overrides”.
  • When a class does not have the “DefaultConfig” tag, its property page on the “Project Settings” dialog will have two extra buttons on the top area:
    • Set as Default: Saves all settings to the corresponding “<PROJECT>/Config/Default<CATEGORY>.ini” config file.
    • Reset to Defaults: Loads all settings from the corresponding “<PROJECT>/Config/Default<CATEGORY>.ini” config file.
  • When a class does not have the “DefaultConfig” tag, changes to its properties through the “Project Settings” dialog can be immediately saved on the corresponding “<PROJECT>/Saved/Config/<PLATFORM>/<CATEGORY>.ini” file. This is meant to persist overrides from one Editor session to the next (not supposed to be checked into source control or shared among users).

Up to UE 5.3, all settings from a non-DefaultConfig class were always included in the “Saved/Config” folder. This could result in huge bloated config files. To avoid this, starting with UE 5.4, you must now opt-in to persist the contents of each config section (this is probably what you are missing). To do that, you must edit file “<PROJECT>/Config/Default<CATEGORY>.ini” and add the following:

[SectionsToSave]
+Section=/Script/PluginModule1.ClassName1
+Section=/Script/PluginModule2.ClassName2

In your case, it should probably look something like this:

[SectionsToSave]
+Section=/Script/RenderPassSettings.UVRenderPassSettings

Note that this opt-in system is enabled by default in file “<ENGINE>/Engine/Config/Base.ini”, where you can find the following:

[SectionsToSave]
bCanSaveAllSections=false

If everything else fails, you can temporarily disable the opt-in system by changing the above to “true” to see if that is really the cause of your config files not being saved.

Let me know if this helps!

Best regards,

Vitor

Hello, Vitor. Tnx for reply, SectionsToSave solved the issue