My Background Music Freezes the Unity Editor

Hello everyone! I’m hoping i could get help with something

At the moment in my game, I’m trying to get background music to work. What i want is to have the background music playing continually and not restart when i jump from one scene to another. Now I’ve written a script which does this, but whenever i leave my menu screen and load up level one of my game, the whole game in the unity editor freezes. So I’m usually forced to hit stop to regain control. What is weird though is that it only does this for all the scenes that are actual playable levels in my game. The editor doesn’t freeze when i jump from different option screens/scenes accessible from my main menu, but the moment i hit my play button which leads to a playable scene, it just freezes. Basically, what i wanted to know is if there was anything you knew of that would cause the game to freeze like that when carrying over a game object that has an audio source in it. i’m guessing, there is something I’ve got within those scenes and not in others that is causing this, but i just can’t figure out what it is. Here is the code. I have an audiosource attached to a gameobject, with which this script is also attached

public class BackgroundMusic : MonoBehaviour {

static bool AudioBegin = false;
public AudioSource BM;

voidAwake() {

if (!AudioBegin) {
BM.Play ();
DontDestroyOnLoad (gameObject);
AudioBegin = true;
}
}

void Update () {

if(Application.loadedLevelName == “GameOverScreen”)
{
BM.Stop();
AudioBegin = false;
}
}

}

Also, im using a wav music file that is 44.1khz, 16bit and about 6 minutes long. I should note too that the editor will freeze even if i remove BM.play() from the script. Anyways, any help would be appreciated. Thanks!

Thanks for that info dude.
But one question, “What is the file size, of your 6 min. long audio sample?” :sunglasses:

Hey Brandy,

its 63mb BUT, i should note that .wav was not the first file type i was using. I was first using an mp3 version of the music that was only 5.8mb and i was still getting the same issue.