Modifying the DefaultEngine.ini through a utility widget

Hello,
I’m trying to save some time updating my project’s version through an editor utility widget .
Currently I manually set the version through the editor’s project settings window and type whatever version I want in the Description → Project Version field.

I have written a function to increment the current version number but unfortunately it only writes the new data to a temp file located in Project\Saved\Config\Windows\Game.ini.
The updates are registered to DefaultGame.ini only after restarting the editor which is undesirable.

This is how I read and write the data at the moment:

FString UMiscLib::GetProjectVersion()
{
	FString ProjectVersion;
	GConfig->GetString(
		TEXT("/Script/EngineSettings.GeneralProjectSettings"),
		TEXT("ProjectVersion"),
		ProjectVersion,
		GGameIni
	);
	return ProjectVersion;
}

void UMiscLib::SetProjectVersion(FString Version)
{
	const TCHAR* NewVersion = *Version;
	
	GConfig->SetString(
		TEXT("/Script/EngineSettings.GeneralProjectSettings"),
		TEXT("ProjectVersion"),
		NewVersion,
		GGameIni
	);

	GConfig->Flush(true, GGameIni);
	
	UE_LOG(LogConfig, Warning, TEXT("New version is %s"),*GetProjectVersion());
}

How would I go about affecting the DefaultGame.ini directly, and is that even possible through a blueprint function library?

Thanks in advance :slight_smile:

If you are looking to edit the config files in the saved/config folder:

if (!GConfig) return false;
    
GConfig->SetString(
        TEXT("/Script/EngineSettings.GameMapsSettings"), //section
    	TEXT("GameDefaultMap"), //Setting Name
    		TEXT("value string goes here"), //Value
    		GEngineIni //file to save
    		);
GConfig->Flush(false, GEngineIni); // Save the config file

If you are looking to edit the config folders in the root config folder:
Look for your setting in the engine settings module
https://docs.unrealengine.com/4.27/en-US/API/Runtime/EngineSettings/

in build.cs under PrivateDependencyModuleNames.AddRange
you need
EngineSettings

and your function will look something like this: (I needed one for setting packaging maps so I used UGameMapsSettings | Unreal Engine Documentation)

bool UOVFPPluginBPLibrary::VPOVFPSetPackagingMap(FString mapPath)
{
	UGameMapsSettings::SetGameDefaultMap(mapPath);
	return true;
}

Either way, wrap them in a blueprint library function like you did with reading the file

  • Adding to this answer: If the setting you want to change is still unavailable you can edit it in the following way:
  • In the UE project/editor settings find the setting and note down the name/tool tip
  • In visual studio search the entire solution for the tool tip or name (tool tip is usually better) and step through until you find the setting you want. Note the type of the setting
  • Once you find the setting, find what class it is located under. Then search that on the UE4 C++ API for the class name
  • From there you will get the module and include files you need.
  • Put the module in the build.cs file as before and the include line in the include section of your blueprint function.cpp
  • then you can use GetMutableDefault<Class>->SettingName = variable/value to get or set

eg. I needed to change the maps to cook setting (UE4 Api)

  • In the module I put UnrealEd, in the include section I put #include “Settings/ProjectPackagingSettings.h”
  • In my blueprint function I added TArray mapstocook to my function inputs
    and used

GetMutableDefault()->MapsToCook = mapstocook;

  • to set the value, or

return GetMutableDefault()->MapsToCook;

  • to bring the value back into the blueprint

For the different ini files here are their variable names:

// Runtime/Core/Private/Misc/CoreGlobals.cpp
FString       GEngineIni;                         /* Engine ini filename */

/** Editor ini file locations - stored per engine version (shared across all projects). Migrated between versions on first run. */
FString       GEditorIni;                         /* Editor ini filename */
FString       GEditorKeyBindingsIni;                    /* Editor Key Bindings ini file */
FString       GEditorLayoutIni;                     /* Editor UI Layout ini filename */
FString       GEditorSettingsIni;                     /* Editor Settings ini filename */

/** Editor per-project ini files - stored per project. */
FString       GEditorPerProjectIni;                   /* Editor User Settings ini filename */

FString       GCompatIni;
FString       GLightmassIni;                        /* Lightmass settings ini filename */
FString       GScalabilityIni;                      /* Scalability settings ini filename */
FString       GHardwareIni;                       /* Hardware ini filename */
FString       GInputIni;                          /* Input ini filename */
FString       GGameIni;                         /* Game ini filename */
FString       GGameUserSettingsIni;                   /* User Game Settings ini filename */

This should help you update the ini files. However I found that although it writes to the ini file directly (in my case the EditorPerProjectUserSettings.ini) changes in the editor or closing reverts the changes. It seems like there is a cache that gets saved to disk and using this function changes the values on disk but not the ones in cache. Using Flush didn’t update it in the cache for me. I’m getting the same keys being replaced whether I’m using the snippet above to write to the ini file or using python to do the same.

I’ll update if I can figure out how to properly propagate the values to the config cache for proper saving.

1 Like