Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by AtomicMarine · Apr 18, 2011 at 06:36 PM · scenesoundlevelmusic

Playing music while scenes change?

If I start a music track in one level and the next level starts, can I have the track not stop and continue playing through to the next level?

Is this possible in Unity?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
6
Best Answer

Answer by synapsemassage · Apr 18, 2011 at 09:25 PM

Something like this works in my game, attach it to a GameObject that won't be destroyed:

public var SoundClip : AudioClip; private var SoundSource : AudioSource;

function Awake() { DontDestroyOnLoad(gameObject); SoundSource = gameObject.AddComponent(AudioSource); //SoundSource.playOnAwake = false; //SoundSource.rolloffMode = AudioRolloffMode.Logarithmic; //SoundSource.loop = true; }

function Start() { SoundSource.clip = SoundClip; SoundSource.Play(); }

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Talavang · Mar 23, 2013 at 09:39 PM 0
Share

worked for me too.

Thanks

avatar image Romario07122001 · Jun 05, 2014 at 04:51 PM 0
Share

thx you helped me a lot

avatar image meatball · Jul 17, 2014 at 09:00 AM 0
Share

works perfect!

Thx a lot

avatar image
3

Answer by DaveA · Apr 18, 2011 at 06:40 PM

I'd try this: http://unity3d.com/support/documentation/ScriptReference/Object.DontDestroyOnLoad.html

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AtomicMarine · Apr 18, 2011 at 08:59 PM 0
Share

So Theoretically if I have an object that I attach a script that would play the game music, If I didn't destroy the object the music would still continue through the scenes? Interesting... But If I load a level and it doesn't load fast enough or I don't have pro and it doesn't load async the music will stop for a brief amount of time? I will test this out thanks for the answer.

avatar image DaveA · Apr 18, 2011 at 09:12 PM 0
Share

I believe that would be correct, but please let us know how it works for you.

avatar image
3

Answer by TowerOfBricks · Apr 18, 2011 at 06:48 PM

Though playing music while the scene changes (i.e when loading after Application.LoadLevel call) doesn't work unless you have pro and can load the level async.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AtomicMarine · Apr 18, 2011 at 09:01 PM 0
Share

$$anonymous$$y scene change times are very fast due to the nature of my game usually 0.1 seconds so I don't think the music stopping for that time would be noticeable, But if I don't destroy the object that is playing the music (Like DaveA suggested) will it restart the song on new load or will it continue playing? I suppose with a good function it could just continue. Thanks for your answer :) I will test this stuff out.

avatar image
0

Answer by madflyskills · Jun 12, 2013 at 11:20 PM

You could take a look at SoundManagerPro, it handles that kind of stuff

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

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

UI Button deletes Function on start 1 Answer

Random level select 1 Answer

Can I use SoundCloud music for my game or showcase ? 0 Answers

Music player giving indexoutofbounds error 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges