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