Can you save custom variable inside a custom GameUserSettings class?

Hi. I created a custom GameUserSettings class, to save stuff like the field of view and the mouse sensitivity in there. Now my problem is that ue4 only saves the standart stuff like texture quality, resolution, screenmode etc. Basicly all of my custom variables dont save. So my question is: Can you save custom variables inside a custom GameUserSettings class ? Also can you save a array of structs inside the GameUserSettings class ?

GameUserSettings is just perticilar class to keep configuration, in reality config system can be used with any UObject class you like. Similar to UBlueprintFunctionLibrary people seems to think you need to use that function to make global blueprint nodes where you can do so in any class, just make function static.

To use config system first you need to declere in which ini file it should storeed in UCLASS specifier

UCLASS(config=GameUserSettings)

Then properties that should be stored in config should be marked with config specifier too

UPROPERTY(config)
uint32 LastUserConfirmedResolutionSizeY;

It might be the thing you missing ;p this way you can control what is saved and what is not. Btw you can flag blueprint made variables as config too, just click varable and in properties extend the error and there should be checkbox for it.

Then you can call SaveConfig() and LoadConfig() functions to save and load config. This is something that blueprint is missing, you can only mark variables to be saved, but you need ot use C++ to actually save it

Again you can do this in any UObject class, you just need to remember that this is class wide, all objects create from the file will load and save config from same place, this don’t need to be config at all you can store anything you like it’s just one way of saving things. But UGameUserSettings is best place for game config indeed and what you trying to do, but it constructed exacly the way i menationed:

https://github.com/EpicGames/UnrealEngine/blob/f794321ffcad597c6232bc706304c0c9b4e154b2/Engine/Source/Runtime/Engine/Classes/GameFramework/GameUserSettings.h

Btw this is just quick way to use full config system, so there no need to write same save and load code over and over again for each class. It can be accessed from GConfig which allows you to read and write any varables from unreal config ini files

1 Like