[4.8.3] Why are Configs emptied when game runs?

Im learning and testing how to work with the config files for my game.
After packaging the project, the config files themselves show up fine after first run.
However, if I exit the game and look in GameUserSettings.ini (where I am placing most of my settings) it is completely empty.
If I reload the game and goto the options menu, click my “apply” button and exit, then the GameUserSettings.ini file now has all of the settings. Cool.

But if I once again reload, then immediately exit, the GameUserSettings.ini file once again is completely empty.
Ive check over all my functions for exit and startup and Ive added nothing that messes with the config files.
It only writes to the config files when you click the “apply” button in the options menu.
(In fact, I do not recall writing anything at all that would just completely clean the GameUserSettings.ini)

Is there a step I am missing that could be causing this?

It looks as if the GameUserSettings.ini is emptied at game start, but that doesn’t make sense to me…
Why would it be emptied if it is meant to permanently store data when the game is not running?

Hey Erdrik,

I’ve found a few resources that may be helpful to you as far as getting your configuration settings to save:

https://impetus-games.com/blog/Persistent-Graphics-Settings-in-UE4

A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums,Read%26_Write_to_Config_Files

If you still have additional questions after looking through that information, feel free to let me know.

Thanks!

The closest thing I could find that is related is the Flush command from the second link, but it doesn’t explain why the Ini is cleared when all i do is load and then exit the game.

If nothing in my code is altering the Ini(because all I do is quit once the game has loaded), why is it getting emptied?

Ok. I did some testing and got some interesting results:

In my GameInstance Init() function, I added code that first checks for a made up test bool at a made up category and key: TestCatagory, and TestValue. It checks for this in Game.ini.

If it does not find it, the code will call SetBool() and adds it to Game.ini.

It then does the same thing for a different made up test bool at another made up category and key: /Script/Engine.GameUserSettings, and bTAAType.

But this time it checks in GameUserSettings.ini.

I packaged as a debug build so I could see the AddOnScreenDebugMessage tracking the results. one set after each check and each setting of the made up bools.(total of 4)

|—

First load of game:

-The first AddOnScreenDebugMessage shows that the first made up variable is not found at first load, as expected.

-The second AddOnScreenDebugMessage shows the code has succeeded in setting the first made up variable in Game.ini.

-The third AddOnScreenDebugMessage shows that the second made up variable is not found at first load, as expected.

-The fourth AddOnScreenDebugMessage shows the code has succeeded in setting the second made up variable in GameUserSettings.ini.

|—

Second load of game:

-The first AddOnScreenDebugMessage shows that the first made up variable was saved and has been found. Working as it should.

-The second AddOnScreenDebugMessage is not shown as the first made up variable was found and there is no need to set it.

-The third AddOnScreenDebugMessage shows that the second made up variable was not saved and has not been found.

-The fourth AddOnScreenDebugMessage shows the code has succeeded in setting the second made up variable in GameUserSettings.ini. This indicates a failure as it should have already found the previously set variable.

Thanks a lot for providing the additional information and performing the additional testing!

What location are you saving your config files to? Could you provide the folder path?

The project configs are at:

(defaults)D:\Documents\Unreal Projects\DMagic 4.8\Config

D:\Documents\Unreal Projects\DMagic 4.8\Saved\Config\Windows

|–

The debug build configs are at:

(defaults)D:\Work\Unreal4Engine\builds\WindowsNoEditor\DMagic\Config

D:\Work\Unreal4Engine\builds\WindowsNoEditor\DMagic\Saved\Config\WindowsNoEditor

I think I may have solved my issue.

I noticed while copying the DIR paths for my last comment, that the GameUserSettings.ini did not have a default ini in the defaults folder, but the Game.ini did. So I manually made DefaultGameUserSettings.ini in my projects DIR, rebuilt the project and it started working.

I guess for any ini to work you must have a default varient present in the defaults folder?

As an aside, I know how to use the global variables to select which ini I read and write from.(GGameUserSettingsIni, GGameIni, ect) But how do I select a new custom ini filename? Do I include the directory path? the .ini? I know the global variables are just FStrings, but Im not sure what they include…

After spending some time testing this myself, I noticed the same behavior. I’m glad that you were able to figure it out.

Let me know if you run into this issue again.

Have a great day

Set the gameusersettings.ini to Read Only