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:
    933
    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:
    38,742
    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.
     
    VAPX007 likes this.
  3. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    1,304
    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
    Tom163, Fluttershy28, Aleko74 and 6 others like this.
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    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.
     
    Aleko74 and angrypenguin like this.
  5. Vinicius_Araujo

    Vinicius_Araujo

    Joined:
    Feb 23, 2020
    Posts:
    3
    For those who get this error message just do the following:

    1- Find your audio source and double click to open

    2022-03-31_22h25_44.png

    2- Look for 'Exposed Parameters' in the upper right corner of the Audio Mixer tab

    2022-03-31_22h26_37.png

    3- Expand the 'Exposed Parameters' select the parameter you are trying to access by the script and change the name to the same name you used in the script (or change the name in the script to the name that appears in the Exposed Parameters)

    2022-03-31_22h28_25.png

    4- Voilà

    2022-03-31_22h33_30.png
     

    Attached Files:

  6. Lasko1

    Lasko1

    Joined:
    Dec 30, 2021
    Posts:
    5
    Thank you so much!
     
  7. Aleko74

    Aleko74

    Joined:
    Oct 27, 2016
    Posts:
    1
    Thanks a lot!!! This is very helpful :)
     
  8. pix3llc3ll

    pix3llc3ll

    Joined:
    Nov 10, 2022
    Posts:
    2
    Helped me a lot ty!