Custom GameUserSettings

Hello! Followed this tutorial to make custom GameUserSettings - https://www.youtube.com/watch?v=7rRUE2FKOXQ

And what is my problem/question… i want to add to this settings possibility to change/save anti aliasing method (r.AntiAliasingMethod 0-4) (also i want to set/get variable of antialiasing in BP) i see something similar in original GameUserSettings, but how can i do this with anti aliasing method?..

(pic from original gameusersettings)

I would be glad if someone could help me! (i am new, i was tried to make this for so many times and nothing. )

.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();
}


Thank u very much! but i have some errors, what i am doing wrong?


(think it’s 100% my bad, but i am new and i don’t know really good engine and c++ ;D)

Did you generate the class through new c++ class from the editor?

Just creating the files in the solution is not enough. Unreal needs to create the .generated files for there to not be errors.

Either make a fresh class based on UGameUserSettings from the editor or try to re-generate the project from the uproject file.

Fixed! no errors, it’s was my bad (i was need to type API with uppercase) but another problem, maked some test widget with this function, and it’s not working, just making nothing

also i noticed this: If i put on the cast function string node, it will not display text on player’s viewport (seems like cast function just not works)

and if i try to put value from antialiasingmethod to print string it types - None


Did you change the project user settings to the new c++ one? Also you need to set the antialiasing method at some point (it is in a different part of the ini file)

If you get stuck for a longer time i can send you a working project.

Edit: Also no need to call any of the settings on tick.

A quickly converted old project that demonstrates the setting of AA and saving / loading

Edit : => Zip file remastered in lower message
Don’t mind the name it was just an old project that was adapted to the user settings. Chain link fence shows the changes an aa quite well.

oh sorry, my interned is bad and i dont see your message, on my project i tried all and nothing, also when i was opened packaged project it was just crashed, i will test ur project, one second

wait, maybe version of engine is problem? i am in unreal 5.3


crashing when i try to open in unreal 5.3

You need to regenerate the project. Right click the uproject file an regenerate the solution.
The test project is in 5.3.2.
Open the solution file in your ide and build the project.

I deleted the temp folders Intermediate, DerivedDataCache, saved and binaries to reduce size. They will regenerate with the project.

Edit: Ok so it seems that if the saved folder is absent it will produce the error on load. I’ll try to add an extra ensure to have it work with fresh projects

Edit: Ok found that with a zero save file it would go into a load settings loop causing the overflow. Just commented out the apply settings on load and it’s fixed
cannonTest.zip (2.0 MB)

regenerated and opened solution with build, anyway crash (i noticed when unreal starts to load it just start to load on 81-83% and after 1-2 min - crash

ok, second

Fixed in the above file ^ ^ :slight_smile:

it’s opening and working! i will try to package it, because in my packaged project i am getting crash and error

seems to work fine! but how to make to load settings from config? because when i startup packaged game AA stays to default (i see on the chain, it’s not anti-aliased, in config is all ok… it’s saving, but it’s not loading from cgf.)

I’ve noticed that even though the config file is saved and update when changes are made it seems to reset on initial load losing the value of the AA in game. Looking into it.

I noticed this too! i am trying to fix this, but in this moment i dont have any good result

cannonTest_V2.zip (2.1 MB)
Ok so I was able to get it working in a packed build

Turned out the console command had to be called from the blueprint otherwise it doesn’t trigger.
Also swapped out the GetAntiAliasingMethod to directly access the variable.

1 Like

Thank u very very much! :smiley: it’s working perfect. Last question what i have… can i add in future another custom setting? (like r.Shadow.Virtual.Enable) i will need to use same code like for anti-aliasing?

Sure why not. It should have a similar process to it.