Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

QualitySettings.antiAliasing = 0; not working

Discussion in 'General Graphics' started by Jay cloth, Dec 5, 2015.

  1. Jay cloth

    Jay cloth

    Joined:
    May 27, 2015
    Posts:
    12
    I am having a problem with a toggle function in a settings menu. The toggle recognises and reacts when it is enabled however when you disable it, it doesn't recognise that it is off or react to it. I have been having problems for days and it is starting to get on my nerves. Here is the code:
    Code (csharp):
    1.  
    2. public Canvas options_nav;
    3.     public Canvas graphics_menu;
    4.     public Toggle option_antialiasing;
    5.     public Button exit;
    6.  
    7.     void Start()
    8.     {
    9.         options_nav = options_nav.GetComponent<Canvas>();
    10.         graphics_menu = graphics_menu.GetComponent<Canvas>();
    11.         option_antialiasing = option_antialiasing.GetComponent<Toggle>();
    12.         exit = exit.GetComponent<Button>();
    13.         options_nav.enabled = false;
    14.     }
    15.  
    16.     public void optionantialiasing()
    17.     {
    18.         if(option_antialiasing == false)
    19.         {
    20.             QualitySettings.antiAliasing = 0;
    21.         }
    22.         else
    23.         {
    24.             QualitySettings.antiAliasing = 4;
    25.         }
    26.     }
    27.  
    The else statement works fine and turns on Anti-Aliasing however the if statememnt doesn't I have set unity to have anti-aliasing set to 0 by default and the toggle is set to off by default so it must be in the code or a bug with Unity.
     
  2. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    You are checking for the toggle, not for its state.

    if(option_antialiasing.isOn == false)...
     
  3. TimGS

    TimGS

    Joined:
    Apr 24, 2014
    Posts:
    70
    it should be like:
    Code (csharp):
    1. if(QualitySettings.antiAliasing != 0)
    2. {
    3.     QualitySettings.antiAliasing = 0;
    4. }
    5. else
    6. {
    7.     QualitySettings.antiAliasing = 4;
    8. }
    instead

    It's wrong to evaluate if class is true or false.
     
    Last edited: Dec 6, 2015
  4. Jay cloth

    Jay cloth

    Joined:
    May 27, 2015
    Posts:
    12
    Thank you so much. That has been annoying me for ages and in a game as big as this with only 2 people building it we are really struggling Thank you so much! :)
     
  5. TimGS

    TimGS

    Joined:
    Apr 24, 2014
    Posts:
    70
    Also, if you want to set it according to your toggle state then it should be like Carpe Denius said.