Search Unity

Music Stops Playing When Application Loads New Scene

Discussion in 'Scripting' started by unityandyou, Jan 11, 2011.

  1. unityandyou

    unityandyou

    Joined:
    Jun 25, 2010
    Posts:
    50
    Hi,

    I have a problem, i want one track of music to play throughout the whole game. but when a hit the "winner" zone and move to the next level. the music stops. how do i fix this?


    Thanks!,

    Colin
     
  2. Jesse Anders

    Jesse Anders

    Joined:
    Apr 5, 2008
    Posts:
    2,857
    I have a suspicion that there's a bug in Unity that affects audio source components associated with game objects that have been made persistent using DontDestroyOnLoad().

    However, I have no idea if that's the problem in this case. Can you provide some more info about the context, such as how you're going about playing music across levels, etc.? (Or, maybe you could just upload a Unity package demonstrating the problem.)
     
  3. unityandyou

    unityandyou

    Joined:
    Jun 25, 2010
    Posts:
    50
    Im trying to get it to play music and not stop when i load the next level.

    so when i load Level 2. i dont want the music to stop.
     
  4. Jesse Anders

    Jesse Anders

    Joined:
    Apr 5, 2008
    Posts:
    2,857
    I know what you're trying to do :) The question is, how are you going about doing it? (We can't very well tell you why it's not working if we have no idea what you're doing.)

    If you're not sure how to explain it, post it as a Unity package so that we can take a look.
     
  5. unityandyou

    unityandyou

    Joined:
    Jun 25, 2010
    Posts:
    50
    Heres what im trying to do (and if i dont explain it right ill post the package),

    Im trying to keep the music playing throught the whole game. i dont want it stoping when i win a level. basicly.i want it to run in the background. and never stop. i hope thats anoth info for you.
     
  6. unityandyou

    unityandyou

    Joined:
    Jun 25, 2010
    Posts:
    50
    Nevermind. I got it fixed. Thanks sooooo much! :D
     
  7. Quietus2

    Quietus2

    Joined:
    Mar 28, 2008
    Posts:
    2,058
    It's good form to explain what you did, so others who come after you with the same issue will have a solution.
     
  8. hizral

    hizral

    Joined:
    Apr 27, 2010
    Posts:
    568
    What did you do and how do you approach on solving the problem, really like to know how you do it.

    thanks.
     
  9. unityandyou

    unityandyou

    Joined:
    Jun 25, 2010
    Posts:
    50
    heres my script:
    function Start () {

    audio.Play();
    }

    function Awake () {
    DontDestroyOnLoad (transform.gameObject);
    }
     
  10. kingoftaurus

    kingoftaurus

    Joined:
    Jan 3, 2011
    Posts:
    104
    funny though how when asked HOW he was loading the sound, he gave us the same explanation over and over. heh. oh
     
  11. xiaoken

    xiaoken

    Joined:
    Jun 1, 2013
    Posts:
    3
    I know this is an old thread but I thought I'd through this out there. I had the same problem today but realized I accidentally was using a 3D sound for music. Make sure it's a 2D sound or if you want 3D that an audio listener is nearby the audio source in the next scene.
     
  12. Cuttlas-U

    Cuttlas-U

    Joined:
    Apr 11, 2017
    Posts:
    38
    hi;
    I had the same problem but i think mine was about an error with DontDestroyOnLoad();

    i had a footstep sound that needed to continue playing while changing the scene ;

    so it stop playing after changing and after trying several ways to fix it what finally solve it was change the

    Compression Format to "PCM"

    and load type to "Streaming"

    hope it helps ;
     
  13. ayush0369

    ayush0369

    Joined:
    Mar 8, 2020
    Posts:
    1
    I Fixed this issue by removing the Audio listener component from Camera and adding it to the GameObject to which the AudioSource was attached... Basically the AudioListener component always should be there. (i.e. AudioListener and AudioSource both should be DontDestroyOnLoad, also there can be only one AudioListener at one instance which you all already know I hope)


    Thanks,
    Ayush Visen
     
  14. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Usually you want your AudioListener with the camera for 3D sounds from the camera's perspective. If all sounds are 2D only in your entire game, then I suppose it doesn't really matter.