How to set default values for structure fields from config (*.ini) in blueprints.

Hi there. I have the following problem. I want users of my plugin to be able to change default structure values from the settings of the plugin. The problem is that I don’t actually understand how to do this. I found the article on this forum, but it didn’t help me.

Now my code looks like this:

The structure which should always have the correct default values of variables from the setting of the plugin:



USTRUCT(BlueprintType)
struct FMySettings
{
    GENERATED_USTRUCT_BODY()

    UPROPERTY(EditAnywhere, BlueprintReadWrite, config)
    float DelayBeforDisplaying;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, config)
    bool bShowShadow;
};


The class which will represent the setting for a user:



UCLASS(BlueprintType, config = Game, defaultconfig)
class UCustomGameSettings : public UObject
{
    GENERATED_BODY()

public:
    UCustomGameSettings(const FObjectInitializer& ObjectInitializer);

    UPROPERTY(config = Game, EditAnywhere, Category = Custom, DisplayName = "Default MBS Settings")
    FMySettings SettingsMBS;
};


Settings registration in the system:



 if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
        {
            ISettingsContainerPtr SettingsContainer = SettingsModule->GetContainer("Project");

            SettingsContainer->DescribeCategory("CustomSettings",
                FText::FromString("CustomSettings"),
                FText::FromString("Game configuration for the CustomSettings game module"));

            ISettingsSectionPtr SettingsSection = SettingsModule->RegisterSettings("Project", "CustomSettings", "General",
                FText::FromString("General"),
                FText::FromString("Base configuration for our game module"),
                GetMutableDefault<UCustomGameSettings>()
            );

            if (SettingsSection.IsValid())
            {
                SettingsSection->OnModified().BindRaw(this, &FMySettingsPluginModule::HandleSettingsSaved);
            }
        }


Settings display, change and save to DefaultGame.ini:

[ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“data-tempid”:“temp_143618_1532927769242_618”,“title”:“Changed-properties-from-Settings.png”}[/ATTACH]
https://forums.unrealengine.com/core/image/gif;base64

Ini file review. The settings were entered correctly:

[ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“data-tempid”:“temp_143619_1532927967829_139”,“title”:“Saved-properties.png”}[/ATTACH]
https://forums.unrealengine.com/core/image/gif;base64

Variable creation in blueprint. Default values aren’t the same as in the settings:

[ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“data-tempid”:“temp_143620_1532928499130_572”,“title”:“Show-wrong-default-properties.png”}[/ATTACH]
https://forums.unrealengine.com/core/image/gif;base64

Also, I’d like the correct default values of my structure to be displayed in Inputs or Outputs:

[ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“data-tempid”:“temp_143621_1532928715932_45”,“title”:“Input-func-properties.png”}[/ATTACH]
https://forums.unrealengine.com/core/image/gif;base64

Or to set settings in the function via Make:

[ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“data-tempid”:“temp_143622_1532928836306_817”,“title”:“Input-func-properties-via-Make.png”}[/ATTACH]
https://forums.unrealengine.com/core/image/gif;base64

I’d be happy to receive any help or ideas. Thanks.



UPROPERTY(config = Game


Tha is wrong.
You mark a class/struct with “config = INI’s name”, correct…
But it’s member UProperties you simply mark “config”.

So:



UCLASS(BlueprintType, config = Game)
{
UPROPERTY(config)
myProperty
}


Then within your class Constructor, you need to call:
LoadConfig();

Btw, I’m not sure if custom struct types are supported like that.

Thanks for youre answer.
This is my code. Is it correct? Unfortunately, your idea didn’t work.



USTRUCT(BlueprintType)
struct FMySettings
{
    GENERATED_USTRUCT_BODY()

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MBS|Settings", config)
    float DelayBeforDisplaying;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MBS|Settings", config)
     bool bShowShadow;
};

UCLASS(BlueprintType, config = Game, defaultconfig)
class UCustomGameSettings : public UObject
{
    GENERATED_BODY()

public:
    UCustomGameSettings(const FObjectInitializer& ObjectInitializer)
    {
         this->LoadConfig(UCustomGameSettings::StaticClass());
    }

    UPROPERTY(config, EditAnywhere, DisplayName = "Default Settings")
    FMySettings SettingsMBS;
};


Default values of the structure aren’t displayed in Inputs, Outputs or Make Struct etc.
Does anybody else have any ideas?

If you want to use a config property in blueprints you need to mark it either BlueprintReadOnly or BlueprintReadWrite. Making it a config property only exposes it within project settings.


UPROPERTY( config, EditAnywhere, BlueprintReadonly, Category = "Strings", meta = (ConfigRestartRequired = true, EditCondition = "bSomeBool") )
FString stringProperty;