Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Assetbundle not affected by quality changes (Webgl)

Discussion in 'Asset Bundles' started by OBJVISION, Mar 5, 2021.

  1. OBJVISION

    OBJVISION

    Joined:
    Oct 5, 2020
    Posts:
    7
    Hi,
    I have got some problem while changing quality settings runtime.
    If i use a model from project it works fine but when model is downloaded from asset bundle the quality does not change on build but work on editor.
    The asset bundle contain the mesh and the texture , i create the object runtime after asset bundle download.
    Here's the code:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class QualityAutomator : MonoBehaviour
    4. {
    5.     public bool automate = true;
    6.     // The min and max frameRate determines at what point it will switch up or down
    7.     public double maxFrameRate;
    8.     public double minFrameRate;
    9.     // Sometimes, there are lag spikes that happen over one or two frames,
    10.     // but are not necessarily related to the quality settings. The
    11.     // switchThreshold is the number of frames in a row that must be too
    12.     // slow or fast before a switch occurs.
    13.     public int switchThreshold;
    14.  
    15.     int upCounter;
    16.     int downCounter;
    17.  
    18.     int maxQualityLevel;
    19.     int currentQualitySettings = 0;
    20.  
    21.     private void Start()
    22.     {
    23.         Debug.Log("CURRENT QUALITY LEVEL = " + QualitySettings.GetQualityLevel());
    24.         maxQualityLevel = QualitySettings.names.Length - 1;
    25.         SetQualityLevel(0);
    26.     }
    27.  
    28.     void Update()
    29.     {
    30.  
    31.         if (Input.GetKeyDown(KeyCode.C))
    32.         {
    33.             Debug.Log("QUALITY SETTINGS COUNT = " + QualitySettings.names.Length);
    34.         }
    35.  
    36.  
    37.         if (Input.GetKeyDown(KeyCode.A))
    38.         {
    39.             automate = !automate;
    40.             Debug.Log("AUTOMATE = " + automate);
    41.         }
    42.  
    43.         if (Input.GetKeyDown(KeyCode.Q)) {
    44.             Debug.Log("CURRENT Texture size LEVEL = " + QualitySettings.masterTextureLimit);
    45.         }
    46.  
    47.         if (Input.GetKeyDown(KeyCode.Plus))
    48.         {
    49.             IncreaseQualityLevel();
    50.         }
    51.  
    52.         if (Input.GetKeyDown(KeyCode.Minus))
    53.         {
    54.             DecreaseQualityLevel();
    55.         }
    56.  
    57.         if (Input.GetKeyDown(KeyCode.Alpha0))
    58.         {
    59.             SetQualityLevel(0);
    60.         }
    61.  
    62.         if (Input.GetKeyDown(KeyCode.Alpha1))
    63.         {
    64.             SetQualityLevel(1);
    65.         }
    66.  
    67.         if (Input.GetKeyDown(KeyCode.Alpha2))
    68.         {
    69.             SetQualityLevel(2);
    70.         }
    71.  
    72.         if (automate) {
    73.  
    74.             AutomateQualitySettings();
    75.         }
    76.     }
    77.  
    78.  
    79.     void AutomateQualitySettings() {
    80.         if ((1 / Time.smoothDeltaTime) > maxFrameRate)
    81.         {
    82.             upCounter++;
    83.             if (upCounter > switchThreshold && currentQualitySettings < maxQualityLevel)
    84.             {
    85.                 IncreaseQualityLevel();
    86.                 upCounter = 0;
    87.             }
    88.         }
    89.         else
    90.         {
    91.             upCounter = 0;
    92.         }
    93.         //Debug.Log(upCounter);
    94.  
    95.         if ((1 / Time.smoothDeltaTime) < minFrameRate)
    96.         {
    97.             downCounter++;
    98.             if (downCounter > switchThreshold && currentQualitySettings > 0)
    99.             {
    100.                 DecreaseQualityLevel();
    101.                 downCounter = 0;
    102.  
    103.             }
    104.         }
    105.         else
    106.         {
    107.             downCounter = 0;
    108.         }
    109.     }
    110.  
    111.     void IncreaseQualityLevel() {
    112.        
    113.         Debug.Log("INCREASE Quality settings");
    114.         QualitySettings.IncreaseLevel();
    115.         currentQualitySettings = QualitySettings.GetQualityLevel();
    116.         Debug.Log("New quality level = " + QualitySettings.GetQualityLevel());
    117.     }
    118.  
    119.     void DecreaseQualityLevel() {
    120.         Debug.Log("DECREASE Quality settings");
    121.         QualitySettings.DecreaseLevel();
    122.         currentQualitySettings = QualitySettings.GetQualityLevel();
    123.         Debug.Log("New quality level = " +QualitySettings.GetQualityLevel());
    124.     }
    125.  
    126.     void SetQualityLevel(int qualityLevel) {
    127.         Debug.Log("Set quality to level " +qualityLevel);
    128.         QualitySettings.SetQualityLevel(qualityLevel);
    129.         currentQualitySettings = QualitySettings.GetQualityLevel();
    130.         Debug.Log("New quality level = " + QualitySettings.GetQualityLevel());
    131.     }
    132. }