Changing DefaultEngine.ini from C++ / UAssetGuideline implementation

Hi,

I’m trying to make changes to a project defaultEngine.ini from a C++ function, however appear unable to do so.

Having followed guidance here (Feed Detail) , it may be that there is now a setting to lock config files from saving however even still I’ve not been able to see a change. For instance, the following code does not appear to make any change to my project defaultEngine.ini:

`FConfigFile* ConfigFile = GConfig->FindConfigFile(GEditorIni);
ConfigFile->bCanSaveAllSections = true;

// Path to the DefaultEngine.ini file
const FString IniFilePath = FPaths::ProjectConfigDir() / TEXT(“DefaultEngine.ini”);

if (GConfig)
{
GConfig->SetBool(TEXT(“/Script/Engine.RendererSettings”), TEXT(“r.MobileHDR”), false, GGameIni);
GConfig->Flush(false, GGameIni);
UE_LOG(LogGlauconOpenXR_EditorPluginSettings, Log, TEXT(“GConfig Valid”));
}
else
{
UE_LOG(LogGlauconOpenXR_EditorPluginSettings, Log, TEXT(“Invalid GConfig”));
}

UE_LOG(LogGlauconOpenXR_EditorPluginSettings, Log, TEXT(“Settings should have updated”));`

It may be that there are better ways to ensure that certain project settings can be changed - ideally, I want a plugin I’m developing to enforce certain project settings on a project if that plugin is present.

I’ve seen that it might be possible to link certain project setting requirements to .uassets however the documentation appears limited however I am struggling to find any way to link UAssetGuideline uassets to other Unreal assets.

Hi David,

Here is what you are looking for:

`URendererSettings* RendererSettings = GetMutableDefault();

RendererSettings->bMobilePostProcessing = false;
FProperty* Property = RendererSettings->GetClass()->FindPropertyByName(GET_MEMBER_NAME_CHECKED(URendererSettings, bMobilePostProcessing));

RendererSettings->UpdateSinglePropertyInConfigFile(Property, RendererSettings->GetDefaultConfigFilename());`

This code modifies the already loaded structure and updates the single property in DefaultEngine.ini. I recommend that your code notifies the user that he needs to restart the editor when the setting is changed.

Martin

It should be possible to do it through GConfig but I couldn’t figure it out when I researched your case. All the examples I could find in the engine code where using the technique I shared.

You do have to be cautious about adding entire sections as this “freezes” the project on the current engine default and it can lead into not using newer features when the project is updated to a new release.

Many thanks - I’ve done it that way in the past however was wanting to add in sections if they weren’t there etc (eg add DLSS config data which might not be present otherwise and therefore I also assume not directly accessible like URendererSettings?

Assuming that GConfig is not the best approach?