Developer Settings are a quick and easy way of creating Project-wide settings that show up under Project Settings.
You could use them for creating defaults that your game uses that are not tied to a particular game mode, and without having to make a custom subclass of Game Instance
Basic Version
Required:
- Subclass
UDeveloperSettings. - Set
CategoryNamethrough the constructor. Also setting SectionName is a good idea. - Add some properties tagged with
EditAnywhereandConfig. - Tag your class with
ConfigandDefaultConfig.
You can create multiple subclasses of UDeveloperSettings to keep unrelated settings in separate files.
MyGameSettings.h
#pragma once
#include "Engine/DeveloperSettings.h"
#include "MyGameSettings.generated.h"
UCLASS(config=Game, DefaultConfig)
class UMyGameSettings : public UDeveloperSettings
{
GENERATED_BODY()
public:
UMyGameSettings(const FObjectInitializer& ObjectInitializer);
protected:
UPROPERTY(Config, EditAnywhere)
int32 DogCount = 0;
};
MyGameSettings.cpp
#include "MyGameSettings.h"
UMyGameSettings::UMyGameSettings(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
// Large text for where settings should be grouped on the left
CategoryName = "Project";
// Smaller sub-heading for grouping
SectionName = "Some Settings";
}
I would recommend setting CategoryName to "Project" so your settings show up in the standard "Project" category at the top of the list. Otherwise if you set CategoryName to something new, it will appear at the bottom of the settings list.
Using In-game
To access these settings in-game, you can use the following:
const UMyDeveloperSettings* Settings = GetDefault<UMyDeveloperSettings>();
Settings->DogCount ... // do something with this
Advanced Version
This way allows you to change the name that is shown in the left-hand list.
MyGameSettingsAdvanced.h
#pragma once
#include "Engine/DeveloperSettings.h"
#include "MyGameSettingsAdvanced.generated.h"
UCLASS(config=Game, DefaultConfig)
class UMyGameSettingsAdvanced : public UDeveloperSettings
{
GENERATED_BODY()
public:
//~ Begin UDeveloperSettings interface
virtual FName GetCategoryName() const;
#if WITH_EDITOR
virtual FText GetSectionText() const override;
virtual FText GetSectionDescription() const override;
#endif
//~ End UDeveloperSettings interface
protected:
UPROPERTY(Config, EditAnywhere, Category="Dog-related Settings")
int32 DogCount = 0;
UPROPERTY(Config, EditAnywhere, Category="Dog-related Settings")
FName DefaultDogId = "Bingo";
};
MyGameSettingsAdvanced.cpp
#include "MyGameSettingsAdvanced.h"
FName UMyGameSettingsAdvanced::GetCategoryName() const
{
return TEXT("Project");
}
#if WITH_EDITOR
FText UMyGameSettingsAdvanced::GetSectionText() const
{
return NSLOCTEXT("MyGameSettingsAdvanced", "SomeDoggySettings", "Doggy Settings");
}
FText UMyGameSettingsAdvanced::GetSectionDescription() const
{
return NSLOCTEXT("MyGameSettingsAdvanced", "SomeDoggySettingsDescription", "Everything related to dogs within the game.");
}
#endif