Saving settings in GameUserSettings.ini

Hi,

I’m trying to implement game settings with GameUserSettings class. Basically it’s the same as in ShooterGame example: I’ve implemented my own MyGameUserSettings : public UGameUserSettings class that handles fullscreen, resolution and a few scalability settings. Changing all that works as expected, however saving settings does not change the appropriate Saved/Config/Windows/GameUserSettings.ini.

I thought that I’m missing smth. basic here so I went to see how that works in the ShooterGame (latest one, with UE4.6) and it turns out settings are not saved there either. Clicking on “Apply Changes” in the game will call UGameUserSettings::SaveSettings() which itself will call void FConfigCacheIni::SetString() (ConfigCacheIni.cpp : 1616) at some point that looks like:

void FConfigCacheIni::SetString( const TCHAR* Section, const TCHAR* Key, const TCHAR* Value, const FString& Filename )
{
	FConfigFile* File = Find( Filename, 1 );

	if ( !File )
	{
		return;
	}

	FConfigSection* Sec = File->Find( Section );
	if( !Sec )
		Sec = &File->Add( Section, FConfigSection() );
	FString* Str = Sec->Find( Key );
	if( !Str )
	{
		Sec->Add( Key, Value );
		File->Dirty = 1;
	}
	else if( FCString::Stricmp(**Str,Value)!=0 )
	{
		File->Dirty = (FCString::Strcmp(**Str,Value)!=0);
		*Str = Value;
	}
}

It turns out that else if( FCString::Stricmp(**Str,Value)!=0 ) check always returns false because saved and new values are equal? I don’t quite understand how that happens because the values that are stored in the ini-file are clearly different from the new ones.

Any ideas on what I’m doing wrong?

Best regards

Hi ,

I have been investigating something similar. Are you manually calling SaveSettings, or are you relying on the UGameUserSettings::ApplySettings saving it for you?

The ApplySettings path only saves after setting the resolution/ full screen settings. It doesnt save when applying the others for a few reasons. I asked a question about there here: Game User Settings doesnt save all changes - Programming & Scripting - Epic Developer Community Forums

But in the short term, what you want to do after you call ApplySettings is:

	Scalability::SaveState(GGameUserSettingsIni);
	GEngine->GetGameUserSettings()->SaveSettings();