How to add custom settings in Project Settings?

Hi there!

I was able to accomplish this and I will do my best to explain what needs to be done, or at least what I did to get it to work. (I will also link my sources)

The first thing I did was follow these tutorials: Unreal Engine 4 adds custom settings to project settings - Programmer Sought + Plugins | Unreal Engine Documentation.

These tutorials show you how to create a plugin and how to set up your settings.

The plugin I created is called TestPlugin (.cpp/.h) and this is what the code looks like:

TestPlugin.h

// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include "Modules/ModuleManager.h"

class FTestPluginModule : public IModuleInterface
{
public:

	/** IModuleInterface implementation */
	virtual void StartupModule() override;
	virtual void ShutdownModule() override;
};

TestPlugin.cpp

// Copyright Epic Games, Inc. All Rights Reserved.

#include "TestPlugin.h"
#include "TestPlugin_Settings.h"
#include "ISettingsModule.h"

#define LOCTEXT_NAMESPACE "FTestPluginModule"

void FTestPluginModule::StartupModule()
{
	// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module

	if(ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
	{
		SettingsModule->RegisterSettings("Project", "Plugins", "TestPlugin_Settings",
			LOCTEXT("RuntimeSettingsName", "My Setting Page"), LOCTEXT("RuntimeSettingsDescription", "Configure my setting"),
			GetMutableDefault<UTestPlugin_Settings>());
	}
}

void FTestPluginModule::ShutdownModule()
{
	// This function may be called during shutdown to clean up your module.  For modules that support dynamic reloading,
	// we call this function before unloading the module.

	if(ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
	{
		SettingsModule->UnregisterSettings("Project", "Plugins", "TestPlugin_Settings");
	}
}

#undef LOCTEXT_NAMESPACE
	
IMPLEMENT_MODULE(FTestPluginModule, TestPlugin)

You also need to create a settings class (this class is referenced in the above code so make sure you have this as well before trying to compile anything). This settings class should derive from UObject, and in my case, I called it TestPlugin_Settings (.cpp/.h)

TestPlugin_Settings.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "TestPlugin_Settings.generated.h"

/**
 * 
 */
UCLASS(config = MySetting)
class TESTPLUGIN_API UTestPlugin_Settings : public UObject
{
	GENERATED_BODY()

public:
	UTestPlugin_Settings(const FObjectInitializer& obj);

	UPROPERTY(Config, EditAnywhere, Category = "My Custom Settings")
	bool CustomBoolFlag;

	UPROPERTY(Config, EditAnywhere, Category = "My Custom Settings")
	int32 CustomInteger;
};

TestPlugin_Settings.cpp

#include "TestPlugin/Public/TestPlugin_Settings.h"

UTestPlugin_Settings::UTestPlugin_Settings(const FObjectInitializer& obj)
{
	CustomBoolFlag = false;
	CustomInteger = 0;
}

After you have created these classes, you should then add the plugin to your .uproject file; here is mine: [Please ignore all other plugins except for “TestPlugin”]

	"Plugins": [
		{
			"Name": "GameplayAbilities",
			"Enabled": true
		},
		{
			"Name": "DarkerNodes",
			"Enabled": true,
			"MarketplaceURL": "com.epicgames.launcher://ue/marketplace/content/4b3441f0228a40ec9ca986489a5bd682"
		},
		{
			"Name": "MagicNode",
			"Enabled": true,
			"MarketplaceURL": "com.epicgames.launcher://ue/marketplace/content/38f49e7411bc47588e0d219758d6b16f"
		},
		{
			"Name": "ElectronicNodes",
			"Enabled": true,
			"MarketplaceURL": "com.epicgames.launcher://ue/marketplace/content/5cb2a394d0c04e73891762be4cbd7216"
		},
		{
			"Name": "TestPlugin",
			"Enabled": true,
			"MarketplaceURL": ""
		}
	]

Now you should be able to recompile, and after its done you should have these accessible properties:

PluginsList

Now, in order to access these properties you need to do the following:

In your project’s build.cs file, you need to add the plugin. Here is mine:

// Copyright Epic Games, Inc. All Rights Reserved.
// Copyright Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;

public class Hero : ModuleRules
{
	public Hero(ReadOnlyTargetRules Target) : base(Target)
	{
		PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

        PublicDependencyModuleNames.AddRange(new string[] { "GameplayAbilities", "GameplayTags", "GameplayTasks", "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay", "UMG", "Slate", "SlateCore", "AIModule", "TestPlugin"});

        MinFilesUsingPrecompiledHeaderOverride = 1;
        bUseUnity = true;
    }
}

Now for my example, I am logging these two settings in the Output Log when my player character is possessed. First, I need to include the plugin:

include “TestPlugin/Public/TestPlugin_Settings.h”

Then, I need to initialize a reference to the plugin. Again, I do this inside of the PossessedBy(AController* New Controller) function within my character:

UTestPlugin_Settings* Plugin_Settings = GetMutableDefault<UTestPlugin_Settings>();

if(Plugin_Settings->CustomBoolFlag)
{
UE_LOG(LogTemp, Warning, TEXT(“My Custom Bool = true”));
}
else
{
UE_LOG(LogTemp, Warning, TEXT(“My Custom Bool = false”));
}

UE_LOG(LogTemp, Warning, TEXT(“My Custom Integer = %i”), Plugin_Settings->CustomInteger);

Now you should be able to compile and when my character is spawned/possessed, the log prints out:

Log
Which matches the settings that I had earlier.

Here are my sources again that I used, and I hope this answers your question/was helpful. Good luck!

23 Likes