Redigging this, because I need more help with my custom GUS.
Upon launching the game, my custom game instance (CndGameInstance) calls the CndSysSave_GameUserSettings function BPF_OnGameLaunched() which does this:
void UCndSysSave_UserSettings::BPF_GUS_OnGameLaunched()
{
bool GUS_Exists = BPF_GUS_DoesExist();
if (!GUS_Exists)
{
UE_LOG(LogTemp, Log, TEXT("CND_DEBUG: GUS - Exists? = NO. Creating .ini file in: %s"), *GUS_FilePath);
BPF_GUS_SetupIniFile();
}
else
{
UE_LOG(LogTemp, Log, TEXT("CND_DEBUG: GUS - Exists? = YES. Loading settings."));
}
}
bool UCndSysSave_UserSettings::BPF_GUS_DoesExist()
{
// Set a custom name for the user settings ini file
GUS_FilePath = FPaths::ProjectConfigDir() + GUS_CndIniName;
GGameUserSettingsIni = GUS_FilePath;
//FString IniFileLocation = FPaths::GeneratedConfigDir() + UGameplayStatics::GetPlatformName() + "/" + GGameUserSettingsIni + ".ini";
bool FileExists = FPlatformFileManager::Get().GetPlatformFile().FileExists(*GGameUserSettingsIni);
return FileExists;
}
void UCndSysSave_UserSettings::BPF_GUS_SetupIniFile()
{
BPF_GUS_RunBenchmark();
Cnd_Version = 1;
// Write the initial version to the custom ini file
GConfig->SetInt(*GUS_Section_CndGame, *GUS_Key_Version, Cnd_Version, GGameUserSettingsIni);
BPF_GUS_Version_Update();
}
void UCndSysSave_UserSettings::BPF_GUS_Version_Update()
{
// Validate user settings to the current version.
Cnd_Version = UE_CND_GAMEUSERSETTINGS_VERSION;
// Write updated version to the custom ini file
GConfig->SetInt(*GUS_Section_CndGame, *GUS_Key_Version, Cnd_Version, GGameUserSettingsIni);
GConfig->SetString(*GUS_Section_CndGame, *GUS_SampleText_Key, *GUS_SampleText_Value, GGameUserSettingsIni);
// Write to disk
GConfig->Flush(true, GGameUserSettingsIni);
}
Thing is, the file is not created right away, but only when the editor/game exits. Is there any way I can force the Unreal to create it without exiting, or is it normal?
My Custom Benchmark setup:
void UCndSysSave_UserSettings::BPF_GUS_RunBenchmark()
{
// Run Benchmark
GUS_Default = GEngine->GetGameUserSettings();
GUS_Default->RunHardwareBenchmark(); // This populates the scores
// Delay score retrieval to allow benchmark to complete
FTimerHandle TimerHandle;
FTimerDelegate TimerDel;
TimerDel.BindUObject(this, &UCndSysSave_UserSettings::BPF_GUS_AutoDetect, true);
GetWorld()->GetTimerManager().SetTimer(TimerHandle, TimerDel, 1.0f, false);
}
void UCndSysSave_UserSettings::BPF_GUS_AutoDetect(bool BenchmarkRunned)
{
if (BenchmarkRunned)
{
FString CPUName = FPlatformMisc::GetCPUBrand();
float CPUScore = GUS_Default->GetLastCPUBenchmarkResult();
FString GPUName_Default = FPlatformMisc::GetPrimaryGPUBrand();
FString GPUName_Actual = GRHIAdapterName;
float GPUScore = GUS_Default->GetLastGPUBenchmarkResult();
FString RHIName = GDynamicRHI->GetName();
FString DebugMessage = FString::Printf(TEXT(
"[CND_DEBUG: GUS - Benchmark Results]\n"
"CND_DEBUG: GUS - Benchmark - CPU NAME: %s\n"
"CND_DEBUG: GUS - Benchmark - CPU SCORE = %f\n"
"CND_DEBUG: GUS - Benchmark - GPU NAME (DEFAULT): %s\n"
"CND_DEBUG: GUS - Benchmark - GPU NAME (ACTUAL): %s\n"
"CND_DEBUG: GUS - Benchmark - GPU SCORE = %f\n"
"CND_DEBUG: GUS - Benchmark - RHI: %s\n"
),
*CPUName,
CPUScore,
*GPUName_Default,
* GPUName_Actual,
GPUScore,
*RHIName
);
UE_LOG(LogTemp, Log, TEXT("%s"), *DebugMessage);
if (CndFunc::Conditions::IsValue_RangedBetween(GPUScore, 0.0f, 50.0f))
{
// Low settings
}
else if (CndFunc::Conditions::IsValue_RangedBetween(GPUScore, 50.0f, 100.0f))
{
// Medium settings
}
else if (CndFunc::Conditions::IsValue_RangedBetween(GPUScore, 100.0f, 150.0f))
{
// High settings
}
else if (GPUScore > 150.0f)
{
// Ultra settings
}
}
}