Search Unity

Getting warning : Exposed name does not exist: Volume but I did expose volume to script why ?

Discussion in 'Scripting' started by Chocolade, Nov 29, 2019.

  1. Chocolade

    Chocolade

    Joined:
    Jun 19, 2013
    Posts:
    655
    The script :

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.Audio;
    6. using UnityEngine.UI;
    7.  
    8. public class SettingsMenu : MonoBehaviour
    9. {
    10.     public AudioMixer audioMixer;
    11.     public Dropdown resolutionDropDown;
    12.  
    13.     [SerializeField]
    14.     private Slider _volumeSlider;
    15.     [SerializeField]
    16.     private Dropdown _dropDownQuality;
    17.  
    18.     private Resolution[] resolutions;
    19.  
    20.     private void Start()
    21.     {
    22.         resolutions = Screen.resolutions;
    23.         resolutionDropDown.ClearOptions();
    24.  
    25.         List<string> options = new List<string>();
    26.  
    27.         int currentResolutionIndex = 0;
    28.         for (int i = 0; i < resolutions.Length; i++)
    29.         {
    30.             string option = resolutions[i].width + " x " + resolutions[i].height;
    31.             options.Add(option);
    32.  
    33.             if (resolutions[i].width == Screen.currentResolution.width &&
    34.                 resolutions[i].height == Screen.currentResolution.height)
    35.             {
    36.                 currentResolutionIndex = i;
    37.             }
    38.         }
    39.  
    40.         resolutionDropDown.AddOptions(options);
    41.         resolutionDropDown.value = currentResolutionIndex;
    42.         resolutionDropDown.RefreshShownValue();
    43.     }
    44.  
    45.     public void SetVolume()
    46.     {
    47.         float volume = _volumeSlider.value;
    48.         Debug.Log("Volume " + volume);
    49.         audioMixer.SetFloat("Volume", volume);
    50.     }
    51.    
    52.     public void SetQuality()
    53.     {
    54.         int qualityIndex = _dropDownQuality.value;
    55.         QualitySettings.SetQualityLevel(qualityIndex);
    56.     }
    57.  
    58.     public void SetFullScreen()
    59.     {
    60.         Screen.fullScreen = !Screen.fullScreen;
    61.     }
    62. }
    63.  
    The warning is on line 48 :

    Code (csharp):
    1.  
    2. audioMixer.SetFloat("Volume", volume);
    3.  
    Screenshot of the Audio Mixer inspector settings I did expose to the Volume :



    After exposing there is the arrow pointing to the right above the Volume :



    But still getting the warning when running the game and changing the Volume slider.
    It should change the volume in the audio mixer but instead it's showing this warning.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    4,981
    I haven't used mixers and their named properties, but I am suspicious about the warning graphic, specifically what is contained within the quotes in the highlighted question. Your screencap says:

    Expose 'Volume (of Master)' to script

    This makes me think that the name is 'Volume (of Master)' but maybe I'm wrong, as I haven't used this specific mechanism. It should be easy to try and test it.
     
  3. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    983
    If you want to see a list of the exposed parameters to find out what they are called, copy and paste them, or rename them, or delete them, then you can click on the "Exposed Parameters" button on the audio mixer. It's kinda hiding in plain view. It is visible in your screenshots. It's just below "Audio Mixer" at the top. "Exposed Parameters (1)"

    As far as naming params go, try to be pretty specific. "Volume" isn't specific. MasterVolume is specific. You don't want to have to rename things in the future when your mixer grows because you were ambiguous in the beginning. Every time you change a param name you have to also change it in the code that hooks up to that param, so create a decent naming convention from the start.You want to read the name, and be able to know exactly what control it is pointing to on the mixer, without looking at the mixer.
     
    Last edited: Nov 30, 2019
    Kurt-Dekker likes this.
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    4,981
    I agree with 100% of what @Hikiko66 said above, and I want to add this: make a series of const strings in one central class to keep from going insane:

    Code (csharp):
    1. public static class MyMixer
    2. {
    3.   public const string s_MasterVolume = "Master Volume";
    4.   // etc.
    5. }
    That way you only use the variable s_MasterVolume anywhere you need that, and if you do rename stuff, you have one central place to go and be confident you got all places it is used.
     
unityunity