x


[Unity 3] Music playback stops unexpectedly when loading a new level

Has anyone run into problems with audio sources marked as "don't destroy on load" stopping playback spontaneously when a new level is loaded? This would be in reference to (for example) playing a music track continuously from one level to another.

The only relevant thread I could find was this one, in which the OP describes what sounds like the same problem.

I've had some trouble reproducing the behavior consistently, but here are some things I've noticed:

  • Playback seems to stop somewhere between the call to OnDisable() prior to loading the new level and the call to OnEnable() that follows loading the level ('isPlaying' is true in the former and false in the latter).

  • At the point the audio stops, I can see in the inspector that the doppler level and min and max distances for the audio source have been reset from their default values to 0, 0, and .1, respectively.

Has anyone else run into this problem or problems like it? Is it a known bug? (I'll file a bug report, but as this basically means no music across level loads, I'd like to at least try to find out if it's user error, and if not, whether there's a workaround.)

more ▼

asked Oct 15 '10 at 05:08 AM

Jesse Anders gravatar image

Jesse Anders
7.3k 7 17 48

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

If you know what's getting reset, I suppose you can just invoke a function that checks that (on load) and changes it back again.

if(AudioSource.minDistance < x.x){
AudioSource.minDistance = y.y
andSoOn;
} 

Better yet, you can use a case switcher. It's a bit of extra code but it sure beats not having sound.

more ▼

answered Nov 27 '10 at 04:24 PM

azzogat gravatar image

azzogat
933 3 16

Thanks for replying (this was a while ago!). Unfortunately, the problem isn't so much the values that are getting reset (although that's certainly a symptom), but rather that playback stops. Sure, you could check to see if the sound is playing and restart playback if it's not, but unless there's something I don't understand about the audio system, you shouldn't have to do that. (I've submitted a bug report, but meanwhile, the cause of the problem remains a mystery.)

Nov 27 '10 at 07:20 PM Jesse Anders

We're having what looks like exactly the same problem. Any progress on that bug report?

Dec 02 '10 at 07:03 PM Daniel Brauer
(comments are locked)
10|3000 characters needed characters left

Try changing Load Type of sound's AudioImporter to Stream from Disk. Sometimes Unity destroyed the sound from memory while unloading the scene.

Also make sure that your AudioListener is not destroyed.

more ▼

answered Jul 12 '11 at 01:27 PM

jehna gravatar image

jehna
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x744
x453
x329
x160

asked: Oct 15 '10 at 05:08 AM

Seen: 1725 times

Last Updated: Jul 12 '11 at 01:27 PM