Download

Game User Settings to Blueprint Library (make persistent UMG options menu)

I’ve noticed a lot of people is having trouble making a persistent options menu in blueprint. So I’m sharing this small Blueprint function library that exposes the essential functions from Game User Settings to blueprint. Also, you wont need to use the save system as this uses the standard config files system.

This is the Header (Repleace SOMBER_API, with your game API)


#pragma once

#include "GameSettingsManager.generated.h"

USTRUCT(BlueprintType)
struct FQualitySettings
{
	GENERATED_USTRUCT_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Quality Settings")
	int32 AntiAliasingQuality;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Quality Settings")
	int32 EffectsQuality;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Quality Settings")
	int32 PostProcessQuality;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Quality Settings")
	int32 ResolutionQuality;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Quality Settings")
	int32 ShadowQuality;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Quality Settings")
	int32 TextureQuality;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Quality Settings")
	int32 ViewDistanceQuality;

	FQualitySettings()
	{
		//do nothing
	}
};

USTRUCT(BlueprintType)
struct FScreenSettings
{
	GENERATED_USTRUCT_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Screen Settings")
	int32 ScreenSizeX;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Screen Settings")
	int32 ScreenSizeY;

	/** Game window fullscreen mode 0 = Fullscreen 1 = Windowed fullscreen 2 = Windowed 3 = WindowedMirror */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Screen Settings")
	int32 ScreenMode;

	/** Whether to use VSync or not */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Screen Settings")
	bool bUseVSync;

	FScreenSettings()
	{

	}
};

UCLASS()
class SOMBER_API UGameSettingsManager : public UBlueprintFunctionLibrary
{
	GENERATED_UCLASS_BODY()
	
public:	
	
	/** Gets the current Scalability Quality in the engine */
	UFUNCTION(BlueprintCallable, Category = "Quality Settings")
	static FQualitySettings GetQualityLevels();
	
	/** Sets the introduced ScalabilityQuality Settings */
	UFUNCTION(BlueprintCallable, Category = "Quality Settings")
	static void SetQualityLevels(FQualitySettings InSettings);

	/** Gets the current Screen settings in the engine */
	UFUNCTION(BlueprintCallable, Category = "Screen Settings")
	static FScreenSettings GetScreenSettings();
 
	/** Sets the screen settings */
	UFUNCTION(BlueprintCallable, Category = "Screen Settings")
	static void SetScreenSettings(FScreenSettings InSettings);

	/** Applies all non resolution settings */
	UFUNCTION(BlueprintCallable, Category = "Settings")
	static void ApplyNonScreenSettings();

	/** Applies the screen settings */
	UFUNCTION(BlueprintCallable, Category = "Settings")
	static void ApplyScreenSettings();

	/** Applies all the graphic settings */
	UFUNCTION(BlueprintCallable, Category = "Settings")
	static void ApplyGraphicSettings();

};

This is the cpp replace the #include with your game .h file



#include "Somber.h"
#include "GameSettingsManager.h"


// Sets default values
UGameSettingsManager::UGameSettingsManager(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{

}

FQualitySettings UGameSettingsManager::GetQualityLevels()
{
	FQualitySettings OutQuality;

	OutQuality.AntiAliasingQuality = GEngine->GameUserSettings->ScalabilityQuality.AntiAliasingQuality;
	OutQuality.EffectsQuality = GEngine->GameUserSettings->ScalabilityQuality.EffectsQuality;
	OutQuality.PostProcessQuality = GEngine->GameUserSettings->ScalabilityQuality.PostProcessQuality;
	OutQuality.ResolutionQuality = GEngine->GameUserSettings->ScalabilityQuality.ResolutionQuality;
	OutQuality.ShadowQuality = GEngine->GameUserSettings->ScalabilityQuality.ShadowQuality;
	OutQuality.TextureQuality = GEngine->GameUserSettings->ScalabilityQuality.TextureQuality;
	OutQuality.ViewDistanceQuality = GEngine->GameUserSettings->ScalabilityQuality.ViewDistanceQuality;

	return OutQuality;
}

void UGameSettingsManager::SetQualityLevels(FQualitySettings InSettings)
{
	GEngine->GameUserSettings->ScalabilityQuality.AntiAliasingQuality = InSettings.AntiAliasingQuality;
	GEngine->GameUserSettings->ScalabilityQuality.EffectsQuality	  = InSettings.EffectsQuality;
	GEngine->GameUserSettings->ScalabilityQuality.PostProcessQuality  = InSettings.PostProcessQuality;
	GEngine->GameUserSettings->ScalabilityQuality.ResolutionQuality   = InSettings.ResolutionQuality;
	GEngine->GameUserSettings->ScalabilityQuality.ShadowQuality		  = InSettings.ShadowQuality;
	GEngine->GameUserSettings->ScalabilityQuality.TextureQuality      = InSettings.TextureQuality;
	GEngine->GameUserSettings->ScalabilityQuality.ViewDistanceQuality = InSettings.ViewDistanceQuality;
}


FScreenSettings UGameSettingsManager::GetScreenSettings()
{
	FScreenSettings OutSettings;
	FIntPoint Resolution = GEngine->GameUserSettings->GetScreenResolution();
	
	OutSettings.ScreenSizeX = Resolution.X;
	OutSettings.ScreenSizeY = Resolution.Y;
	OutSettings.ScreenMode = int32(GEngine->GameUserSettings->GetFullscreenMode());
	OutSettings.bUseVSync = GEngine->GameUserSettings->bUseVSync;

	return OutSettings;
}

void UGameSettingsManager::SetScreenSettings(FScreenSettings InSettings)
{
	GEngine->GameUserSettings->SetFullscreenMode(static_cast<EWindowMode::Type>(InSettings.ScreenMode));
	GEngine->GameUserSettings->SetScreenResolution(FIntPoint(InSettings.ScreenSizeX, InSettings.ScreenSizeY));
	GEngine->GameUserSettings->bUseVSync = InSettings.bUseVSync;
}

void UGameSettingsManager::ApplyNonScreenSettings()
{
	GEngine->GameUserSettings->ApplyNonResolutionSettings();
}

void UGameSettingsManager::ApplyScreenSettings()
{
	GEngine->GameUserSettings->ApplyResolutionSettings(true);
}

void UGameSettingsManager::ApplyGraphicSettings()
{
	GEngine->GameUserSettings->ApplyNonResolutionSettings();
	GEngine->GameUserSettings->ApplyResolutionSettings(true);
}

Compile and you are good to go. In any blueprint

Call the function GetQualityLevels() and it will return a struct that you can break to get:

. Anti Aliasing Quality.
. Texture Quality.
. Shadows Quality.
. Post Process Quality.
. View distance scale
. Resolution Scale

you can use GetScreenSettings to obtain the current resolution, vsync option and windows mode.

use the SetQualityLevels and SetScreenLevels to make a struct with your values.
After you are done with those values, you can apply the changes with:

. ApplyGraphicSettings - it will apply all the settings you changed.
. ApplyNonScreenSettings - it will apply all the settings that are not refered to resolution
. ApplyScreenSettings - applies all the screen settings (resolution, vsync and windows mode).

Its pretty basic but still, I hope it comes handy to anyone needing something like this. You can easily expand its functionality. Cheers!

Thanks for this! Definitely looks useful.