Hello,
I have the code below.
// Copyright William Antonio Pimentel-Tonche. All rights reserved.
#include "Subsystems/ConnGameInstanceSubsystem.h"
#include "Libraries/ConnFrameworkProjectSettings.h"
#include "GameFramework/GameUserSettings.h"
#include "Types/ConnMacros.h"
#include "Runtime/Launch/Resources/Version.h"
UConnGameInstanceSubsystem::UConnGameInstanceSubsystem():
bRunStartupBenchmark(true),
BenchmarkWorkScale(10),
BenchmarkProcessorWorkScale(1.0f),
BenchmarkVideoWorkScale(1.0f),
bAutoBasicSettingsToMax(true)
{
}
void UConnGameInstanceSubsystem::Initialize(FSubsystemCollectionBase& Collection)
{
Super::Initialize(Collection);
// Get project settings and set instance settings
const UConnFrameworkProjectSettings* FrameworkProjectSettings = GetDefault<UConnFrameworkProjectSettings>();
bRunStartupBenchmark = FrameworkProjectSettings->bRunStartupBenchmark;
BenchmarkWorkScale = FrameworkProjectSettings->BenchmarkWorkScale;
BenchmarkProcessorWorkScale = FrameworkProjectSettings->BenchmarkProcessorWorkScale;
BenchmarkVideoWorkScale = FrameworkProjectSettings->BenchmarkVideoWorkScale;
bAutoBasicSettingsToMax = FrameworkProjectSettings->bAutoBasicSettingsToMax;
// Call the internal start function
OnStart();
}
void UConnGameInstanceSubsystem::RunStartupBenchmark()
{
CF_RETCHECK_VOID(!bRunStartupBenchmark)
UGameUserSettings* Settings = UGameUserSettings::GetGameUserSettings();
CF_RETCHECK_VOID_WITHLOG(!Settings, LogConnFramework, Error, TEXT("No valid game user settings found!"))
Settings->RunHardwareBenchmark(BenchmarkWorkScale);
Settings->ApplyHardwareBenchmarkResults();
}
void UConnGameInstanceSubsystem::InitGraphicsSettings() const
{
UGameUserSettings* Settings = UGameUserSettings::GetGameUserSettings();
CF_RETCHECK_VOID_WITHLOG(!Settings, LogConnFramework, Error, TEXT("No valid game user settings found!"))
if (bAutoBasicSettingsToMax)
{
constexpr int32 MaxQualityConstant = 4;
Settings->SetTextureQuality(MaxQualityConstant);
#if ENGINE_MAJOR_VERSION 5
Settings->SetReflectionQuality(MaxQualityConstant);
#endif
Settings->SetFoliageQuality(MaxQualityConstant);
Settings->SetShadingQuality(MaxQualityConstant);
}
// Allow developers to override using command line.
// This is called in all cases, such as if for any reason dirty settings were left over from some event/script.
Settings->ApplySettings(true);
}
void UConnGameInstanceSubsystem::OnStart()
{
// Run benchmark (if enabled) before initializing graphics settings, since it may change the settings that follow.
RunStartupBenchmark();
InitGraphicsSettings();
}
The purpose of this block of code is to, if the developer so chooses, automatically set certain graphics settings that through my testing seem to do nothing to performance to their maximum setting. One of these settings is SetReflectionQuality, which apparently does not exist in Unreal Engine 4 (I discovered that after trying to port the framework to Unreal Engine 4.22.3). I added this note in the header file for the switch:
/**
* If true, then the following settings will be automatically set to Cinematic graphics at startup.
* To knowledge, these will be clamped to Epic graphics in packaged games, but Cinematic is still usable for renders.
* * Textures
* * Reflections
* * Foliage
* * Shading
*
* When tested with Lumen using the method below, these had a performance impact of nearly (if not) zero milliseconds
* from Low ==> Cinematic. Enabling this setting maximizes quality with minimal performance impact (while also making
* your game's Graphics Settings menu a little smaller)
*
* TESTED ON:
* AMD Ryzen 7 4700U, 16GB DDR4-3200, Integrated Radeon Vega Graphics
* Tested with Marketplace Asset Pack "Horror Forest" by MacKenzie Shirk.
* Your mileage may vary! If issues are encountered, disable this and contact support.
*
* @see Conniption Framework Documentation for more information (especially on the testing method used).
*/
UPROPERTY(Config, Category = "Game Settings|Graphics Settings", EditAnywhere, BlueprintReadOnly)
bool bAutoBasicSettingsToMax;
That setting is in the UConnFrameworkProjectSettings class. I did that test not long ago, on Unreal 5. I saw no noticable difference in framerates or frametimes on my integrated graphics chipset which has to share memory with the rest of my system as it is, and with that considered I decided that it may be useful to include that little feature.
Problem is, I get this error when trying to compile:
ConnGameInstanceSubsystem.cpp(60): [C4067] unexpected tokens following preprocessor directive - expected a newline
Not sure what could be causing this. Any help would be appreciated.
The Version.h include at the top was added to try and remedy this, but it didn’t work.
Note: I will do this performance test again before I actually decide whether or not to retain this feature. If I see similar results - i.e. no noticable difference in framerates/frametimes - I will keep the feature, but otherwise I will remove it if I am proven wrong and may have just been tripping on sleep deprivation.