Daily Unreal Column #61 - GConfig
Unreal's source code has multiple useful global variables. One of them is GConfig that acts as an interface allowing user to read and write things from configuration files.
I’m sure most of you are aware of a folder names Config in your project directory. Inside this directory you can find files like DefaultEngine.ini
or DefaultGame.ini
, and more.
You can use GConfig
global variable to easily read data from any of these. For example, consider adding the following to your DefaultGame.ini
file.
[MyCategoryName]
MyVariable=2
With the above definition of a section (MyCategoryName
) and a variable (MyVariable
) we can use the GConfig
as following in order to read the value.
int32 OutConfigVariable;
const bool bSuccess = GConfig->GetInt(
TEXT("MyCategoryName"),
TEXT("MyVariable"),
OutConfigVariable,
GGameIni);
if (bSuccess)
{
UE_LOG(
LogTemp,
Log,
TEXT("Successfully read MyVariable=%d"),
OutConfigVariable);
}