.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameUserSettings.h"
#include "GameUserSettingsExtended.generated.h"
/**
*
*/
UCLASS(config = GameUserSettings, configdonotcheckdefaults, Blueprintable)
class YOUR_API UGameUserSettingsExtended : public UGameUserSettings
{
GENERATED_BODY()
public:
UGameUserSettingsExtended(const FObjectInitializer& ObjectInitializer);
// Sets the anti-aliasing method
// @param Value 0:none, 1:FXAA, 2:TAA, 3:MSAA, 4:TSR
UFUNCTION(BlueprintCallable, Category = Settings)
void SetAntiAliasingMethod(EAntiAliasingMethod Value);
// Returns the anti-aliasing method
UFUNCTION(BlueprintCallable, Category = Settings)
EAntiAliasingMethod GetAntiAliasingMethod();
UPROPERTY(config)
uint8 AntiAliasingMethod;
UFUNCTION(BlueprintPure, Category = Settings)
bool IsAntiAliasingMethodDirty() const;
//UFUNCTION(BlueprintCallable, Category = Settings)
virtual void LoadSettings(bool bForceReload = false) override;
};
.cpp
#include "GameUserSettingsExtended.h"
#include "Kismet/GameplayStatics.h"
UGameUserSettingsExtended::UGameUserSettingsExtended(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
SetToDefaults();
}
void UGameUserSettingsExtended::SetAntiAliasingMethod(EAntiAliasingMethod Value)
{
static IConsoleVariable* SetAA = IConsoleManager::Get().FindConsoleVariable(TEXT("r.AntiAliasingMethod"));
if (ensure(SetAA))
{
// ECVF_SetByGameSetting , ECVF_SetByCode, ECVF_SetByProjectSetting
SetAA->Set((uint8)Value, ECVF_SetByGameSetting);
SetAA->Set((uint8)Value, ECVF_SetByProjectSetting);
}
UWorld* world = GEngine->GameViewport->GetWorld();
//UWorld* w = GetWorld();
if (world != nullptr) {
if (APlayerController* PC = UGameplayStatics::GetPlayerController(world, 0)) {
PC->ConsoleCommand("r.AntiAliasingMethod " + (int32)Value);
}
}
AntiAliasingMethod = (uint8)Value;
}
EAntiAliasingMethod UGameUserSettingsExtended::GetAntiAliasingMethod()
{
static IConsoleVariable* GetAA = IConsoleManager::Get().FindConsoleVariable(TEXT("r.AntiAliasingMethod"));
if (ensure(GetAA))
{
AntiAliasingMethod = (uint8)GetAA->GetInt();
}
return (EAntiAliasingMethod)AntiAliasingMethod;
}
bool UGameUserSettingsExtended::IsAntiAliasingMethodDirty() const
{
bool bIsDirty = false;
if (GEngine && GEngine->GameViewport && GEngine->GameViewport->ViewportFrame)
{
static IConsoleVariable* GetAA = IConsoleManager::Get().FindConsoleVariable(TEXT("r.AntiAliasingMethod"));
int32 aa = (uint8)GetAA->GetInt();
bIsDirty = (AntiAliasingMethod != aa);
}
return bIsDirty;
}
void UGameUserSettingsExtended::LoadSettings(bool bForceReload)
{
Super::LoadSettings(bForceReload);
static IConsoleVariable* GetAA = IConsoleManager::Get().FindConsoleVariable(TEXT("r.AntiAliasingMethod"));
if (ensure(GetAA))
{
AntiAliasingMethod = (uint8)GetAA->GetInt();
}
ApplyNonResolutionSettings();
}

