• 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
6
Question by defmech · Jul 07, 2010 at 03:31 PM · audioiphoneplayoneshot

audio.Play() not always playing the entire AudioClip

I'm getting very inconsistent results from audio.Play(), audio.PlayOneShot and AudioSource.PlayClipAtPoint. Some times the clip will play through correctly, while other times it will only play a portion and sometimes not at all.

Context: This is for a very simple minigame where the user has to touch targets as they move across the screen. A raycast figures out what they touched and calls a function on the target that plays a Maraca-shake sound, adjusts the score, instantiates an effect popup and at the end, destroys the GameObject. Everything else works perfectly except for the sound. When it doesn't work, it plays such a short portion of the clip that it only sounds like a "tick".

Sometimes I can go an entire play session without an occurrence and other times the problem happens 50% of the attempts, so I know it's not a problem with a specific object/prefab/inspector setting. They're all using the same script with the same settings.

I've tried all three methods of playing the sound listed above and all have the same problem. I've disabled the Destroy command to see if the sound was getting cut off too early, but that didn't work either. I'm not sure what else to try at this point. This is in Unity iPhone 1.7 basic. The error occurs both in the editor and on the device(iPad and iPhone).

Comment
Add comment · Show 3
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 TaigaStudios · Jul 08, 2010 at 07:52 AM 0
Share

Just to make sure, the game objects that you destroy, they don't have the sound clip, do they?

avatar image defmech · Jul 08, 2010 at 05:14 PM 0
Share

Nope, they just have a script that references the AudioClip. I get much better results with PlayClipAtPoint due to how it works compared to the others, but it still glitches at least once or twice in a level.

avatar image Matt 11 · Aug 19, 2010 at 10:43 PM 0
Share

i'm having the same problem, but in a web build. ~$$anonymous$$att

5 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by jtbentley · Aug 29, 2010 at 02:59 AM

If you aren't destroying the gameObject that holds the audio source (my first though), then it could be any of the following.

  1. You're using MP3s (someone else mentioned this).
  2. You're using Play, rather than PlayOneShot(audioClipName). Play one shot can be triggered many times at once, and it'll deal with it. Play can not.
  3. Can you confirm with a line of debug code that you aren't accidentally triggering it 30 times? That would also cause issues.
  4. Are you doing anything to audio anywhere else, such as having an audio listener on the wrong camera, etc?
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
avatar image
2

Answer by BurningThumb · Aug 26, 2010 at 04:48 AM

It may be that the audio buffer becomes full causing an error and cancelling the operation.

In other words the iphone can only play one compressed audio clip at a time, and all sound effects must be uncompressed (AIFF) audio to play simultaneously. The compressed audio is usually used for the background music as it would be larger.

If you try to play an additional audio clip that is compressed the audio processor will have insufficient memory bandwidth or capacity to fulfil the requested operation. Try to limit the number of uncompressed audio clips playing simultaneously to prevent a buffer overflow, and limit compressed audio to one clip only.

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 SomeGuy22 · Nov 03, 2020 at 06:22 AM 0
Share

10 years later and this comment pretty much saved my project, thank you! While I'm building for PC instead of phone, it tipped me off to the idea that compressed audio has a limit within the engine/platform--never encountered that before. For me, I had a lot of sources in my scene using the same clip. Even though they were small and out of range most of the time, they prevented my ambient audio from playing properly. I noticed when I switched my ambient audio to Decompress on Load, the single clip would play fine. But this was not ideal, since I wanted to keep the compression for these long clips. So the solution was to change the out of range audio source clip to Decompress on Load instead of Compressed in $$anonymous$$emory. This gave enough room for the ambient audio to run as Compressed, even though as I mentioned you couldn't even hear the other sources. So ironically, making the clip uncompressed actually helped the audio engine/buffer to leave room for the compressed audio, which in turn allowed them to play properly. What's sad is that none of this gave any warnings or errors in Unity, which is a little scary. The only reason I knew it was happening was because I checked the audio mode in the scene view.

avatar image
0

Answer by s1niz7el2 · Nov 20, 2011 at 10:12 AM

I am having the same problems in an ABC learning game. When the user clicks a button the sound of the letter is supposed to play. It works on most of the letters but not all of them. By changing the bitrate on one of the non-working letters, I was able to get it to work but this "fix" is not consistent. All of the sound files are mp3 and targeted for android devices but I test with PC. Please help.

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 aldonaletto · Nov 20, 2011 at 10:53 AM 0
Share

Are you having this problem in the PC or only when testing in the Android?

avatar image
0

Answer by s1niz7el2 · Nov 21, 2011 at 12:04 PM

I've only tested on the pc. I was able to solve the issue by rerecording the faulty sounds as wav. I'd prefer mp3 for filesize but the 6 letters as wav are doable. I noticed in other posts that it seems that mp3 files are a bit buggy. Is this 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
avatar image
0

Answer by DimitriUK · Jul 17, 2015 at 07:01 PM

(2015)

If you are still having this problem and are using:

GetComponent().Play;

I managed to fix it, because before my gun would shoot it's first bullet and sound weird, and then back to normal, but after 30 seconds, it would go weird again.

What you need to do is where your code is that says:

GetComponent().Play;

You need to have this underneath:

GetComponent ().Play (49); - This is mine anyway. The 49 refers as khz, meaning a delay as well.

So 44100 will give you a delay of exactly 1 second.

I basically divided 44100 by 90 and that has allowed me to have my gun sounds to work as normal.

I hope this helps.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Why PlayOneShot is not working? C# 1 Answer

how to load ogg files from documents folder. 1 Answer

can you stream audio from a person's iphone library 0 Answers

what is wrong with the javascript code? 1 Answer

Help with a simple conversation script? 0 Answers


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