I’ve noticed for the past months of development that a strange loud buzz sound was played upon entering the scene. I could not find any audio I imported for my game causing this.
I tried to change the priority levels of each Audio Source but this did not change anything.
I also tested it in the Editor (version 2021.3.17f on Windows) on two different computers, and as Build on a few other computers, and the same happened, but at different pitch.
Since I could record it while playing the game, I guess it comes from the game itself and is not caused by any hardware issue (also because it happens both in the editor and build, and on different computers).
It’s not an hardware issue. That’s a sound being played/restarted every frame. You just need to find the script that’s playing a sound while the game is initializing. I’m guessing you’re repeatedly resetting a script from within a loop for some reason.
Or if it’s not a bug then you could try fading the title screen volume to zero before switching to the game.
I tried all you said but it didn’t seem to affect this buzz sound.
However, following one of your advise, I concluded that the buzz sound was caused by a specific sound being played, the helicopter sound.
When commenting the line playing it, the buzz sound was absent. And when de-commenting it, it came back. I tested it both in Edit mode and Build.
Here are the mentioned lines:
Intro1Animation.Play("Intro1");
yield return new WaitForSeconds(0.01f); // to avoid buzz
HelicopterSound1.Play();
Here the Intro1Animation uses the helicopter GameObject, of which one of the children is the AudioSource HelicopterSound1. When commenting either line 1 or 3, the buzz sound was absent,
So in short, I added a very short delay between “helicopter animation starts playing” and “helicopter sound starts playing”, and it seems to work.
However, the buzz came back when having more FPS: this solution worked for 60 FPS, but not 200, the maximum for my game. I believe the value inside the WaitForSeconds() should vary depending on the frames per second of the player. For 200, I found that 0.1f worked.
I have no idea what is causing this to happen and why a delay is required. I also tried with other delays such as WaitForEndOfFrame() or null but they did not work. Maybe Unity doesn’t like having an AudioSource playing inside an animated GameObject, at the same time?