Hello,
I’ve wasted a few hours today trying to find a solution, reading a lot of resources and topics on the internet about the GameUserSettings, but nothing worked.
The main issue is that no matter what I try, I cannot get Unreal to create a new .ini file and store variables marked with UPROPERTY(Config) there.
First of all, I have a C++ class:
UCLASS(config=MyUserSettings, BlueprintType)
class MYPROJECT_API UMyGameUserSettings : public UGameUserSettings
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category=Settings)
static UMyGameUserSettings* GetMyGameUserSettings();
UFUNCTION(BlueprintCallable, Category=Settings)
inline FString GetCustomSettingsVariable1() const {return CustomSettingsVariable1;}
UFUNCTION(BlueprintCallable, Category=Settings)
inline void SetCustomSettingsVariable1(const FString VariableValue) { CustomSettingsVariable1 = VariableValue; }
protected:
UPROPERTY(Config)
FString CustomSettingsVariable1;
};
I also changed DefaultEngine.ini to include:
[/Script/Engine.Engine]
GameUserSettingsClassName=/Script/MyProject.MyGameUserSettings
Now, as I understand at this point, whenever I use GetGameUserSettings→ApplySettings in BP, myCustomSettingsVariable1 should be printed to the MyUserSettings.ini file insideSaved\Config\WindowsEditor.
I wasn’t sure if that was enough, so I tried creating the DefaultMyUserSettings.iniin the \Config folder, and add the following to it - to no avail.
[SectionsToSave]
bCanSaveAllSections=true
Surprisingly enough, my CustomSettingsVariable1 is actually added, but to the GameUserSettings.ini in Saved\Config\WindowsEditor folder. Why is that?
Another thing is that along with it, a bunch of other variables are added there, like:
bUseVSync=False
bUseDynamicResolution=FalseCustomSettingsVariable1=0.76
bUseVSync=False
bUseDynamicResolution=False
ResolutionSizeX=2048
ResolutionSizeY=1152
LastUserConfirmedResolutionSizeX=2048
LastUserConfirmedResolutionSizeY=1152
These are under the section:
[/Script/MyProject.MyGameUserSettings]
However, there is still one under the default section:
[/Script/Engine.GameUserSettings]
bUseDesiredScreenHeight=False
I understand they are added there by default, but how do I change which are added there - I mean, shouldn’t there be some way to actually decide which settings are stored in the config and which are not? Well, I (and the hypothethical end user of my product) don’t care about some Resolution and LastUserConfirmedResolution, and DynamicResolution, etc. - all I would need in a config file would simply be ResX, ResY that I can change if need be, without all the other nonsense. As I understand, right now all the settings that are marked with UPROPERTY(Config) in the base UGameUserSettings are added there. But how can I change that?
So, in summary, there are two things/questions:
- how do I make my own, custom variables be saved in a new, custom ini file?
- how do I control which settings (among the engine default ones) are saved at all (or at least which of them are saved to the new, custom file)?