You shouldn’t be assigning values to the config variables within the header file.
You can set default values within the appropriate default config file (in your instance “GAMENAMEGame.ini”, wherein “GAMENAME” is the actual name of your game) under a heading for your class holding the config variables:
[/Script/GAMEMODULE.AMyPlayerController]
superVar=OK
superFloat=999.0f
Replace “GAMEMODULE” with the actual name of your game module.
Then, when you run your game, the values within the config file will be read into the variables in your class.
The values will only appear within the “/Saved/Config/[Platform]/” files if they are different from the default; otherwise the default values will be used.
In order to modify them, you have to use the GConfig global:
if (GConfig)
{
GConfig->SetString(
TEXT("/Script/GAMEMODULE.AMyPlayerController"),
TEXT("superVar"),
TEXT("Not Okay"),
GGameIni
);
GConfig->SetFloat(
TEXT("/Script/GAMEMODULE.AMyPlayerController"),
TEXT("superFloat"),
100.0f,
GGameIni
);
}
GConfig also has SetText, SetInt, SetBool, SetColor, SetVector, and SetRotator to store other types of variables.
FName values should be converted to FString when storing.
The section and key arguments can be held in an FString, but will need to be passed in via pointer. Values are passed normally:
FString Section = TEXT("/Script/GAMEMODULE.AMyPlayerController");
FString Key = TEXT("superVar");
FString Value = TEXT("Not Okay");
if (GConfig)
{
GConfig->SetString(*Section, *Key, Value, GGameIni);
}
After setting the values, you need to flush the config file to ensure they are applied:
if (GConfig)
{
GConfig->Flush(false, GGameIni);
}
Or, from within your UCLASS(Config) object you can call “SaveConfig();”
You can also read from config files into any variable, without using the UCLASS and UPROPERTY specifiers:
FString ValueReceived;
if (GConfig)
{
GConfig->GetString(
TEXT("/Script/GAMEMODULE.AMyPlayerController"),
TEXT("superVar"),
ValueReceived,
GGameIni
);
}
A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums,Read%26_Write_to_Config_Files