- Home /
Audio from new scene begins half way through loading.
Hey,
So, I'm loading in a scene using Application.LoadLevel, and it all works fine, except for one thing. For some reason, the audio from the scene that is currently loading seems to start the moment the audio source has been loaded. This means I get atmospheric sound effects playing during loading. The really odd thing about this is that it seems to totally ignore the AudioListener's state. I have tried both AudioListener.pause
and AudioListener.volume = 0
, and neither solves the issue (the sound does stop after the scene is loaded, but still plays during the loading period). Is there anything I can do to prevent this from happening?
Answer by Hoeloe · May 11, 2014 at 11:32 PM
I have fixed this! The issue arose because I was changing AudioListeners between scenes (I had a different camera setup in each scene, and it was easier to remove the camera than to attempt to change the scripts attached to it on loading the scene). This meant that, when I changed the volume of the AudioListener before loading the scene, it set the volume of the existing AudioListener. But, it then swapped that Listener for a new one, that I had no control over. Once I realised this, it was just a case of adding something along the lines of:
void OnLevelWasLoaded()
{
AudioListener.volume = 1;
}
void Start ()
{
AudioListener.volume = 0;
}
So the volume is set to 0 immediately after the AudioListener is created, and reset again once the level is fully loaded.
Answer by monogon · Apr 28, 2014 at 11:53 PM
Uncheck the box "Play on awake" on your AudioSource. Then play the clip from script when the level has loaded.
That made no difference. Well, almost no difference. It at least pays attention to the AudioListener's volume, to some extent (that is, if, in the new scene, I have the audio volume set to 0, it won't play the sound during loading either). However, it still plays the sound while loading if I don't have the in-game audio volume set to 0.
I don't know why your problem occurs or whether it is a common problem but unless someone has a better fix for it you could try this work-around.
Application.LoadLevel("anyLevel");
AudioSource.volume = 0f;
Then when the level has loaded:
OnLevelHasLoaded(int level) {
AudioSource.volume = 1f;
}
It's a work-aroung but not a very nasty or unstable one I think. You might try it.
Your answer
Follow this Question
Related Questions
How do I only start the audio when player is at max distance 1 Answer
Audio not playing well on AudioListener move 1 Answer
Real time audio source on audio listener.... 0 Answers
Audio: -3db automatic attenuation on any audio playing? 0 Answers
GetSpectrumData or equivalent in non-realtime mode? 2 Answers