Use .json file in plugin content

Hi,
I wrote a plugin for editor and game. I want to read/write some plugin settings to a json file. The plugin file structure is:

 myplugin
     Content/config/my.json
     Content/blueprints/BP_my.asset
     Resources
     Source
     myplugin.uplugin

In editor mode everything works fine. In game mode not. The my.json file is not packaged! How can I package this file to?

Thanks in advance

You need add the directory config into the Directories to never cook list in packaging of project settings.

Then all file in that directory will be packaged.

But I recommend you write a setting class, if the json file is just for configuration.
The setting class was defined like UCLASS(config = MyPluginSettings, defaultconfig). And the property of the setting class was defined like UPROPERTY(Config, EditDefaultsOnly, BlueprintReadOnly).

Thanks c4g.io !

As you recomended, I switched to a settings class. In editor reading and writing properites of my plugin works. I use Engine.ini.

Next step, how to bring these settings, made in the editor, into the packaged game (which includes my plugin)? If I package the game the extended Engine.ini is not included.

Any idea?

Ok, found the answer. To get the plugin settings file copied I have to add it to the MyPlugin.Build.cs

if (Target.Platform == UnrealTargetPlatform.Win64 || Target.Platform == UnrealTargetPlatform.Win32)
{
    string ConfigFile = "$(ProjectDir)/Plugins/MyPlugin/Config/MyPluginSettings.ini";
    RuntimeDependencies.Add(new RuntimeDependency(ConfigFile));
}

And in UCLASS

UCLASS(Config="Plugins/MyPlugin/Config/MyPluginSettings", defaultconfig)

The MyPluginSettings will be generated and saved in [Project]/Config/DefaultMyPluginSettings.ini then the parameter of the settings is changed in the UE4 editor.
You know all ini files is created for the project not the plugin, so it will be saved in [Project]/Config/.

Thanks c4g.io. If I understand the handling of configuration files (UPROPERTY) correctly, it is unusable for plugin settings. For example, using the project config directory,

UCLASS(Config="MyPluginSettings", defaultconfig)

there are at least two problems:

  1. It is not possible to read in default settings which are shipped with the plugin. Default settings have to be in
    my_plugin/Config directory. Though the plugin should look at my_project/Config.

  2. First problem is not too bad. Because the default settings can be hard coded into the plugin. The next problem is to get the config file written to the right place. For example I modify the plugin settings in the Unreal editor. Then the MyPluginSettings.ini is saved at

    my_project/Saved/Config/Windows/MyPluginSettings.ini

If i launch or package the project the MyPuginSettings.ini are expected to be in

my_project/Config/MyPluginsSettings.ini

I dont want to tell the plugin user to hand copy this or modify his project package settings. So how to copy the MyPluginSettings.ini automatically after they are modified, or before launch/package, from

my_project/Saved/Config/Windows

to

my_project/Config

The only way I see is to stay on the plugins/Config directory as I wrote in my previous comment.


My test code for project configuration handling:

MySettings.h

UCLASS(Config="MYPluginSettings", defaultconfig)
class MYPLUGIN_API UMySettings : public UObject
{
	GENERATED_UCLASS_BODY()
	
public:	

	UPROPERTY(Config, BlueprintReadOnly, Category=MyPlugin)
	int32 IntegerSetting;	

    int32 GetIntegerSetting() const;
    void SetIntegerSetting(int32 value;)
};

MySettings.cpp

UMySettings::UMySettings(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
	// maybe set default values, problematic if a .ini file already exist
	//IntegerSetting = 1;
}    

int32 UMySettings::GetIntegerSetting() const {
   	return IntegerSetting;
}
    
void UMySettings::SetIntegerSetting(int32 value) {
	IntegerSetting = value;
	SaveConfig();
}