Update 1 : 27 March 2025
Tried creating the "autodetect graphics preset" feature using fps only.
The logic was pretty simple. Get the average FPS in an interval and check if it was within a certain range. If it was below the range, drop the quality level by 1, it it was above increase the quality level by 1.
I have 5 quality level (0 to 4). So to save some time i set the default quality as 2 so it would be less number of iterations to get to the best graphics preset for that device.
`void AdjustGraphicsSettings(float avgFPS)
{
if (!isAutoDetecting) return;
if (avgFPS < minStableFPS && currentQualityLevel > 0)
{
currentQualityLevel--; // Decrease quality
}
else if (avgFPS > maxStableFPS && currentQualityLevel < QualitySettings.names.Length - 1)
{
currentQualityLevel++; // Increase quality
}
else
{
return; // FPS is stable, no change needed
}
QualitySettings.SetQualityLevel(currentQualityLevel);
Debug.Log($"Adjusting to: {QualitySettings.names[currentQualityLevel]}");
}
`
I made sure to add to add a timer to run this only once every 5 seconds and a total of 3 times.
Problem no. 1: I'm targetting android. Which means when the scene is loaded for the first time theres a bit of lag ( if someone can tell me why that is, that would be awesome ).
Solution : Added a 10 second timer.
Sometimes the best solution is to wait. XD
Problem no 2: Since i'm an indie dev i sadly don't have a box full of devices to test stuff on. So how the hell am I supposed to know if the code I wrote works.
(contd. )