Audio restarting during LoadLevel

Found a very interesting bug in unity…

Let’s say you have a AudioSource attached as a child of a scene camera. But it is set with DontDestroyOnLoad, even though the parent camera is set to be destroyed. When a new scene is loaded, the audio source gets parented to the root. At that point, the AudioSource will be restarted.

So how can this be resolved?

This bug can be worked around by simply resetting the parent to null before LoadLevel is called.