Search Unity

Audio ByPassEffect seems to affect all audio sources

Discussion in 'Audio & Video' started by guittonthomas41, Jan 23, 2020.

  1. guittonthomas41


    Apr 8, 2019
    Hi !
    I am trying to set up a pause menu where I apply a low pass filter on the audio when open.
    The problem is that I want all audio sources to be under the filter effect EXCEPT the sound of the button's hover. In order to do that, I implement a script where I pick the correct audio source (the one that plays when I hover a button) and I enable the byPassEffect on this specific source:

    public class AudioManager : MonoBehaviour{

    Code (CSharp):
    1. //Many other functions
    3. public void ByPassEffect(string name)
    4.     {
    5.         Sound s = Array.Find(sounds, sound => == name);
    6.         if (s == null)
    7.         {
    8.             Debug.LogWarning("Sound" + name + "not found !");
    9.             return;
    10.         }
    11.         s.source.bypassEffects = true;
    12.     }
    13. }

    Then I later call this function with:

    Code (CSharp):
    1. public class ButtonHover : MonoBehaviour
    2. {
    3.     private AudioManager audioManager;
    5.     void Start()
    6.     {
    7.         audioManager = Object.FindObjectOfType<AudioManager>();
    8.         audioManager.ByPassEffect("Hover");
    9.     }
    10.     public void Hover()
    11.     {
    12.         audioManager.Play("Hover");
    13.     }
    14. }
    Everything seems to work properly: my filter is applied when I open my menu, my "Hover" source is not under the filter effect BUT the problem is that when I hover a button, all my sources seems to then have their byPassEffect value on true. The inspector shows empty tick boxes (except for the "Hover" source which is normal) but I can't hear the filter anymore..

    The AudioManager is the one form Brackeys video (+ the homemade ByPassEffect function):

    I have no idea why it behave like that, can anyone please help me ?

    Thank you.