Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
2
Question by jackpile · Mar 17, 2012 at 12:45 AM · timeaudiosourceplaytimescalemute

AudioSources don't play when setting Time.timescale to 0

I'm using the standard trick of setting Time.timescale = 0 to pause my game. Then I present buttons when paused to restart the level, go to the main menu, mute, shop, etc. I want to play a consistent button sound across all UI buttons when clicked, but when in game pause, my button clip doesn't play immediately. I assume that Time.timescale=0 tells Unity to also pause new audiosources. Is there any way around this and to make them play immediately? I can't find anything on the forum or in documentation. Thanks.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by coah · Aug 11, 2013 at 08:59 PM

I got this problem as well today. I found a silly solution.

Just do this;

 Time.timeScale = 1;
 audio.PlayClipAtPoint(sfx.soundTest, Camera.main.transform.position, 1.0 ); 
 Time.timeScale = 0;

The "One Shot Audio" objects accumulate in the hierarchy while the timeScale is 0, but they all go away once the timescale is 1 for a full frame again.

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 yummybrainz · Apr 01, 2014 at 08:58 PM 0
Share

haha nice! Just what i needed. Thanks for sharing!

avatar image
2

Answer by aldonaletto · Mar 17, 2012 at 02:59 AM

AudioSources play independently of Time.timeScale - probably the code that should call Play() is being stopped when timeScale becomes 0. If you use the code below, the sound assigned to audio.clip will be played anytime the button pause is clicked (attach this code to the object that has the AudioSource):

private var pause = false; private var lastValue = false;

function OnGUI(){ pause = GUI.Toggle(Rect(10,10,200,60), pause,'Pause'); if (pause) Time.timeScale = 0.0; else Time.timeScale = 1.0; if (pause != lastValue){ // if pause changed... lastValue = pause; audio.Play(); // play the sound } }

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 jackpile · Apr 18, 2012 at 10:47 PM 0
Share

Thanks! Sorry for replying so late! I have to get in the habit of trying small examples to prove/disprove. $$anonymous$$y bad. I'm too focused on just getting my app out the door after many months. I don't think my code is getting paused as my callbacks from buttons are being issued (EZGUI) and my calls to Play() are being made. Something else must be going on. Cheers.

avatar image downpour · Aug 21, 2014 at 12:02 AM 1
Share

$$anonymous$$y experience has been that AudioSources that already exist play independent of TimeScale. If you're using PlayClipAtPoint() you'll need to toggle the timescale as coah described above, or create the AudioSource component before you set TimeScale to 0.

avatar image
0

Answer by Dannabe1 · Nov 11, 2020 at 09:45 AM

Don't use audioSource.PlayOneShot(audioClip), it will wait until Time.timeScale will be greater than 0. Use audioSource.Play() asigning before audioClip to AudioSource.


Sometimes, people use Time.timeScale = 0f and AudioListener.pause = true or AudioListener.volume = 0. In these cases, you must set these AudioSource properties to true:

 audioSource.ignoreListenerPause = true;
 audioSource.ignoreListenerVolume = true;







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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

AudioSources don't play when setting Time.timescale = 0 1 Answer

Can i ignore timescale when playing AudioSource.PlayClipAtPoint ? 1 Answer

Sound Timing 1 Answer

Audio clip not playing 1 Answer

Lots of !IsFinite() Errors and FPS crawling to a halt - How to debug? 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