How to write to DefaultGame.ini?

(I’m using Unreal 4.27)

I have a class with the following specifiers:

UCLASS(Config=Game, defaultconfig)
class MYGAME_API UConsoleCommandDevSettings : public UDeveloperSettings

GENERATED_BODY()
	
public:
	UPROPERTY(Config, EditAnywhere, BlueprintReadWrite)
	TArray<FBuildCheatCommand> CheatCommands;

The information in the array is currently being saved in the Game.ini file when I call SaveConfig(). However, I wanted it to be saved to the DefaultGame.ini.

The main purpose of this is to save data that is only accessible in editor(UFunction MetaData) to a file that can be used in builds. My understanding is that any modifications that I do to Game.ini during editor play are not transferred to builds, so I have to save it to DefaultGame.ini instead.

Solved:

Instead of calling the SaveConfig() function without arguments, I pass the Default Config file path:

UConsoleCommandDevSettings* ConsoleCommandDevSettings = GetMutableDefault <UConsoleCommandDevSettings>();
... // Rest of the data manipulations

FString DefaultConfigFilePath = ConsoleCommandDevSettings->GetDefaultConfigFilename();

ConsoleCommandDevSettings->SaveConfig(CPF_Config,*DefaultConfigFilePath);

Hope this helps anyone that comes by!

4 Likes