Creating a Custom User Configuration - jgoffeney/Cesium4Unreal GitHub Wiki
Unreal Engine has a built in system for reading configuration / settings files. Default .ini files are generated automatically with a new project in the <Your Project>/Config directory. Variable values can be added to these files and then loaded directly to a class at runtime. However these files are not accessible when a package is generated (I think). But custom files can be created.
- HOW TO CREATE A CUSTOM SETTINGS.INI IN UNREAL ENGINE 4
- UE4 and C++, UPROPERTY (Config, GlobalConfig)
- UE4 Configuration Files
For my use case I wanted to load the base
The project's default setting file are located in the directory <Project Name>/Config/ as:
- DefaultEditor.ini
- DefaultEngine.ini
- DefaultGame.ini
- DefaultInput.ini
Changes to these files are done during development and are baked into the final package.
Custom settings files can be created and are located in similar locations for the project and the package. For the package the directories are generated automatically the first time it runs so if you are adding a custom file you will need to create the directories first.
- Project Custom Settings
- <Project Name>/Saved/Config/<Platform>/
- Package Custom Settings
- <Package Name>/<_Platform_NoEditor>/<Project Name>/Saved/Config/<_Platform_NoEditor>
To use the automatic system then the class needs to be derived from a Unity class with the UCLASS macro. To specify the file name the Config parameter is used. For the default files you discard the Default from the file name. For example to access the DefaultGame.ini settings use the macro UCLASS(Config=Game). For a custom file use the name of the file. In the example below my custom file is CesiumStarter.ini.
To automatically load a variable value the variable has to be declared with a _UPROPERTY macro with the parameter Config (the other UPROPERTY parameters can also be included as well).
The variable values are set within the .ini file (CesiumStarter.ini for my example). I am loading the FString variable called baseDirectory. First the location set as [/Script/<ModuleName>/<ClassName>]. Note it is the name of the module within the project and not the name of the project (they may be the same but may not if the project was moved or cloned). The variable value is set as a key value pair with the key as the variable name and the value is to which the variable is set. Repeat for multiple variables.
[/Script/CesiumCppStarter.TileLoader]
baseDirectory=K:/Data/3dTiles
UCLASS(Config=CesiumStarter)
class CESIUMCPPSTARTER_API ATileLoader : public AActor
{
GENERATED_BODY()
public:
/// <summary>
/// The base directory containing directories of different tile3d tilesets.
/// </summary>
UPROPERTY(Config)
FString baseDirectory;
/// <summary>
/// Constructor
/// </summary>
ATileLoader();