Download

Save/Load data from custom UGameUserSettings

Hi,

I have been following Things To Know In Unreal 4 in order to create my custom game user settings and so far I have:

header for my custom settings



UCLASS()
class CUBEWARS_API UMyGameUserSettings : public UGameUserSettings
{
        GENERATED_BODY()
        
public:

        float GetMasterSoundVolume();
        void SetMasterSoundVolume(float Volume);
        
protected:

        UPROPERTY(config)
        float MasterSoundVolume;

};


and my code for functions



void UMyGameUserSettings::GetMasterSoundVolume()
{
    return MasterSoundVolume;
}

void UMyGameUserSettings::SetMasterSoundVolume(float Volume)
{
    MasterSoundVolume = Volume;
    ApplySettings(false);
}


I also set my game settings to be default. I have created blueprint callable functions that gets and sets value in settings but I always get 0.0 … Am I missing something?

Have you told the project to use your custom Game settings class?

DefaultEngine.ini:



[/Script/Engine.Engine]
GameUserSettingsClassName=/Script/GESGame.SCGame_GameUserSettings


Yes I have added this. But I have not expanded DefaultGameUserSettings.ini. UMyGameUserSettings.ini was not created (dunno if it should). I will double check if I put proper data in DefaultEngine.ini but I will be able to check if in 4h.

Mabe the way I tested it was not correct (both functions are BlueprintPure):



// set test function
...
UMyGameUserSettings * userSettings = Cast<UMyGameUserSettings >(GEngine->GetGameUserSettings());
if (userSettings)
{
    userSettings->SetMasterSoundVolume(15);
}
...
// get test function
...
UMyGameUserSettings * userSettings = Cast<UMyGameUserSettings >(GEngine->GetGameUserSettings());
if (userSettings)
{
    return userSettings->GetMasterSoundVolume();
}
return -1


Try clearing out your config files.

I also suggest increasing the version to force Unreal to clear out existing configs:

HEADER



#define MY_GAMEUSERSETTINGS_VERSION 9	// UE settings + 3

	// Wipes serialized data if version is invalid
	virtual bool IsVersionValid();
	virtual void UpdateVersion();


CPP



bool USCGame_GameUserSettings::IsVersionValid()
{
	return (Version == SC_GAMEUSERSETTINGS_VERSION);
}

void USCGame_GameUserSettings::UpdateVersion()
{
	Version = SC_GAMEUSERSETTINGS_VERSION;
}


By clearing config files you mean to remove all lines from all *.ini files or just user settings one?

Just that one file

Works like a charm! Thanks @TheJamsh! BTW. I also changed exposed funtions from BlueprintPure to BlueprintCallable.