How to change cvars for very early system initialization

We are getting some crashes from users during swap chain initialisation. We assume it’s because AMD’s Fidelity FX Swap Chain feature is the cause as it is enabled by default.

So we’d like to toggle this feature only when the user enables the FSR mode in our game.

For this we need to change the related cvar (r.FidelityFX.FI.OverrideSwapChainDX12) from the in-game setting and upon restart be ready during

SCOPED_BOOT_TIMING("LoadModulesForProject(ELoadingPhase::PostSplashScreen)");inside

FEngineLoop::PreInitPreStartupScreenwhich is too early for our custom GameUserSettings which do normally initialise cvars for us.

This brought us to the general question of this post:

What is Epic’s suggested way for changing and storing cvars during runtime for the next restart when game user settings are not applicable?

I figured the Scalability system starts very early for instance. But it does not set cvars directly but works by reading vars from the GameUserSettings ini and afterwards applying these to the actual cvars through code.

Does this mean the suggested way is to create custom code in a similar fashion? Or are there some onboard methods we could/should use?

For our particular use case we successfully tested modifying the FSR plug-in code by applying this same principle. Though it feels bit awkward to write custom code for this general purpose.

I’m aware of these posts

[Content removed]

[Content removed]

This seems to work:

FConfigFile* ConfigFile = GConfig->FindConfigFile(GEngineIni); ConfigFile->bCanSaveAllSections = true; GConfig->SetInt(TEXT("/Script/FFXFSR3Settings.FFXFSR3Settings"), TEXT("r.FidelityFX.FI.OverrideSwapChainDX12"), FSREnabled, GEngineIni); GConfig->Flush(false, GEngineIni);But from the other posts it sounds like this is not what Epic would suggest to do.

Any clarification appreciated.

Regards

I don’t know much about the actual settings, or what FSR is, but how are you saving that the user enabled it?

Also, for your solution - i definitely recommend against bCanSaveAllSections - instead add this to your DefaultEngine.ini:

[SectionsToSave] +Section=/Script/FFXFSR3Settings.FFXFSR3SettingsThis way only that section will be force saved, and you won’t need to FIndConfigFile.

FN, for isntance, only saves the GUS.ini file to disk in the shipping game.. I am not super familiar with the timing of when GUS.ini settings are read and applied, compared to the SwapChain init, but I would have thought it was generally early enough. Can you move your custom GUS processing earlier?