Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Set game quality level depending on device's capabilities (by code)

Discussion in 'Scripting' started by SeriouslyNot, Jul 7, 2020.

  1. SeriouslyNot

    SeriouslyNot

    Joined:
    Nov 24, 2017
    Posts:
    121
    I came across this post on StackOverFlow when i was trying to make a script to detect device's capabilities and set Quality settings and other settings accordingly.


    I'm using this script to determine Quality level
    Code (CSharp):
    1. public static void AutoChooseQualityLevel()
    2.     {
    3.         var shaderLevel = SystemInfo.graphicsShaderLevel;
    4.         var vRam = SystemInfo.graphicsMemorySize;
    5.         var cpuCount = SystemInfo.processorCount;
    6.         var fillrate = 0;
    7.         if (shaderLevel < 10)
    8.             fillrate = 1000;
    9.         else if (shaderLevel < 20)
    10.             fillrate = 1300;
    11.         else if (shaderLevel < 30)
    12.             fillrate = 2000;
    13.         else
    14.             fillrate = 3000;
    15.         if (cpuCount >= 6)
    16.             fillrate *= 3;
    17.         else if (cpuCount >= 3)
    18.             fillrate *= 2;
    19.         if (vRam >= 512)
    20.             fillrate *= 2;
    21.         else if (vRam <= 128)
    22.             fillrate /= 2;
    23.  
    24.         var resX = Screen.currentResolution.width;
    25.         var resY = Screen.currentResolution.height;
    26.         const float targetFps = 60.0f;
    27.         var fillNeed = (resX * resY + 400f*300f) * (targetFps / 1000000.0f);
    28.         var levelMultiplier = new float[] { 5.0f, 30.0f, 80.0f, 130.0f, 200.0f, 320.0f };
    29.  
    30.         var maxQuality = QualitySettings.names.Length - 1;
    31.         var level = 0;
    32.         while (level < maxQuality && fillrate > fillNeed * levelMultiplier[level+1])
    33.             ++level;
    34.  
    35.         var quality = QualitySettings.names[level];
    36.         qualityLevel = quality;
    37.     }
    :
    But it's not working properly, it gave me "Medium" on Samsung S9 and "Ultra" on a very old Samsung device (i don't really know its model name). It also gave me "Low" on my Macbook pro.

    Plus i don't quite understand the concept used in the code.

    Can i anyone participate in making the function better? or maybe is there another way to determine Quality level?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,008
    Interesting approach, but it conflates CPU count with shader level with RAM... that's weird. I have no idea where the original author would even have gotten that, or even what reasoning would lead him to come up with such a heuristic.

    Also, do you even need to do this in your game? If you're not having performance issues and you're doing this, you are completely wasting your time and inviting more bugs for yourself in the future.

    If you actually ARE having a problem, a far better approach is to attach the Profiler (Window -> Analysis -> Profiler) and see what is slowing you down on lower-end devices, and address that directly. Far less work and far more likely to actually produce good outcomes. The above script is sort of like "Well, I hope this makes it get better," which isn't really engineering, it's more like witchcraft. :)
     
    SeriouslyNot likes this.
  3. SeriouslyNot

    SeriouslyNot

    Joined:
    Nov 24, 2017
    Posts:
    121

    @Kurt-Dekker I totally agree with you on that matter, however, yes i'm having performance issues on lower-end devices because i'm using a somewhat expensive Shader Graphs in my game and i want to disable them or substitute them with cheaper ones if the device is actually a lower-end device, i don't want to sacrifice the eye-candy in the game just to make it run exactly the same on older devices, i want the game to run more beautifully on modern devices and to run with steady FPS with less eye-candy VFX on lower-end devices. (without asking the user to choose quality by themselves).


    Note: i already know what causing the FPS drop in the game, and i made a cheaper shader for that matter that i want to use if the device is a lower-end device.
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I was considering a different approach for an auto-quality level. Pick a target FPS, and when FPS is less than 80% of the target for a significant period of time then drop the quality level, and if above 120% of the target then increase the quality level.
     
    mrstruijk and SeriouslyNot like this.
  5. SeriouslyNot

    SeriouslyNot

    Joined:
    Nov 24, 2017
    Posts:
    121
    Interesting..