Saving Editor settings to the final package app

Hello!

I’ve created a plugin (!). The plugin contains three modules: an editor module, an actor component and a setting class. The editor module allows the configuration of the settings.

Every instance of the actor component query the setting class to get their default settings at runtime.

I use “RegisterSettings” so the properties are also available through the “Project Settings” menu.

Problem is I would like to save the current state of the settings to the final packaged app.

Thanks,

If your Settings UObject is declared inside of your GAME_MODULE, then the settings is always saved to the final packaged app.
To read the settings saved within Editor panels, you get the Settings UOBjects default object and read its values in game:



const auto &Settings = GetMutableDefault<MyPluginSettings>();
Settings->ReadThisVar;


Hmm, sound logicial.

I’ve added IMPLEMENT_GAME_MODULE to both MyPluginSettings module and my actor component module. Same issue. GetMutableDefault<MyPluginSettings>() returns default value even if they were set from the editor before.

I don’t know if that matter but I call GetMutableDefault<MyPluginSettings>() from my actor component.

Maybe I don’t use the setting class correctly then.

To write my settings I use
GConfig->SetBool(TEXT("/Script/coreDSSettings.coreDSSettings"), TEXT(“DisableWord”), mDisableWord ? 1 : 0, GGameUserSettingsIni);
GConfig->Flush(false, GGameUserSettingsIni);

I also tried but when using that approach, settings are not saved at all (even from the Editor)

UcoreDSSlSettingsettings* lSettings = GetMutableDefault<UcoreDSSettings>();
lSettings->myVal = 0;
lSettings->SaveConfig();

I always read using GetMutableDefault<MyPluginSettings>().

Thanks.

1 Like

You don’t need to do all that to save settings;
I declare a Settings object like this (inside a Game Module):



UCLASS(ClassGroup = Settings, Category = "My Plugin", config = Game)
class MYPLUGIN_API MySettings : public UObject {
// stuff...
};


To register the Settings object to the Editor’s Project Settings panel (inside Editor Module):



// stuff....
          bool SaveSettings() {
	  #if WITH_EDITORONLY_DATA
		const auto &Settings = GetMutableDefault<MySettings>();
		**Settings->SaveConfig()**; return true;
	  #endif
	return false;}
	//
	void RegisterSettings() {
	  #if WITH_EDITORONLY_DATA
		if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings")) {
			ISettingsContainerPtr SettingsContainer = SettingsModule->GetContainer("Project");
			SettingsContainer->DescribeCategory("MyNamespace",LOCTEXT("MyNamespaceCategoryName","MyNamespace"),
			LOCTEXT("MyNamespaceCategoryDescription","MyNamespace Systems."));
			//
			ISettingsSectionPtr SettingsSection = SettingsModule->RegisterSettings("Project","MyNamespace","MySettings",
				LOCTEXT("MySettingsName","My Settings"),
				LOCTEXT("MySettingsDescription","General settings for the My Plugin"),
			GetMutableDefault<MySettings>());
			//
			if (SettingsSection.IsValid()) {SettingsSection->OnModified().BindRaw(this,&ThisObject::SaveSettings);}
		}
	  #endif
	}
	//
	void UnregisterSettings() {
	  #if WITH_EDITORONLY_DATA
		if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings")) {
			SettingsModule->UnregisterSettings("Project","MyNamespace","MySettings");
		}
	  #endif
	}


Make sure that your Editor object registration is doing this line:



if (SettingsSection.IsValid()) { ***SettingsSection->OnModified().BindRaw(this,&ThisObject::SaveSettings);*** }


1 Like

Not much luck. Could that matter if my settings are written from an Editor Module then read back, from the package app, from an Actor Component?


UCLASS(ClassGroup = Settings, Category = "My Plugin", config = Game)
class COREDSSETTINGS_API UcoreDSSettings : public UObject
{
	GENERATED_BODY()

public:
	UcoreDSSettings(const FObjectInitializer& ObjectInitializer);
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite, config, Category = Custom)
	bool EnableLogging;

};

Thanks