• 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
0
Question by siege911 · Jun 09, 2013 at 02:03 AM · collisionaudiolag

Collision sound effect lag

I've got a scene where when a ball hits the ground it plays a little bounce sound effect.

My code checks for a collision and then uses SendMessage to tell a sound manager object to play the sound. This "technically" works fine but there is a slight delay in the audio. It's much less than a second but noticeable.

I've checked and edited the audio file so there is absolutely no dead space before the sound effect. The only thing I can think of is Unity is causing the delay. I can't really play the sound just before the collision because I can't anticipate the collision. It's triggered off of the collision itself.

How can I remedy this?

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 bodec · Jun 09, 2013 at 02:14 AM 0
Share

Increase the trigger area so it triggers sooner

avatar image siege911 · Jun 09, 2013 at 02:30 AM 0
Share

How would I do that? It triggers when it collides. I guess I could put a large collider as a Trigger only with no physics but that could trigger off a very close miss. I only want the sound effect when it actually hits the object.

avatar image bodec · Jun 09, 2013 at 02:42 AM 0
Share

Run the sound in the update and the collision in late update I'm guessing here tossing out ideas don't know for sure

2 Replies

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

Answer by Rob Mills Audio · Jun 09, 2013 at 06:30 AM

The most common cause for this case of very slight audio lag is the compression settings. If the engine has to decompress a sound every time it's called, then it will lag slightly before it plays. Try using a decompressed .wav file as your sound, and load the sound to ram on your audio asset's parameter settings. This preps the sound and can be played back instantly with no lag when it is called.

If you are still experiencing a delay - I would suggest you do another 2 quick steps.

Firstly, either look at the waveform using a DAW and see if there is silence within the waveform before the sound starts, or simply try other .wav files to see if they are behaving the same.

Secondly, you can write a quick script to 'play sound on mouse left click'. Listen for any delay. If you have a delay using this super simple script, and your source .wav files have no initial 'silence' in them, then it's most likely your computers sound card that simply delays any audio coming out of it whatsoever.

I would be happy to look at the waveform if you don't know how.

Comment
Add comment · Show 4 · 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 siege911 · Jun 09, 2013 at 10:04 PM 0
Share

Thanks. I've already edited the sound using Audacity. I'll try a WAV file and see how that works but I had a questions regarding "load the sound to ram". How is that accomplished?

I'm using Unity 3.5.7. Haven't upgraded to 4 yet in case there's a difference. Currently I imported the $$anonymous$$P3 sound into Unity and set the "Load Type" to "Decompress on load" which I thought would basically do the same effect as using a WAV file as it doesn't have to decompress on the fly.

I don't see any other options for loading to RA$$anonymous$$ anywhere.

avatar image siege911 · Jun 10, 2013 at 12:00 AM 0
Share

Never $$anonymous$$d my question. The WAV file pretty much fixed everything. And I see the "Load into memory" option under the WAV file as well while it wasn't under the $$anonymous$$P3 file.

avatar image Rob Mills Audio · Jun 10, 2013 at 01:24 AM 1
Share

Well done! Glad to help!

Load to RA$$anonymous$$ / memory is only available for decompressed audio as it can be played back instantly. The delay is almost always because of decompressing into ram as it plays.

Usually it is best to follow a few simple rules.

Short sounds for action on screen should always be .wav and be loaded into ram. movement, attacks, collisions, effects, etc. all need to be able to play instantly with no delay. Being a very short audio clip, the .wav format doesn't take up too much space.

Slightly longer sounds between 5-10 seconds like dialogue, ambient noises, short audio clips etc. CAN be compressed if you don't require INSTANT playback, but are also small enough to use as .wav files anyway without adding too much size to your project. These don't have to be loaded to ram, they can be decompressed on load, which will temporarily use RA$$anonymous$$ as it plays the audio whilst decompressing. In the case of dialogue, usually you'll only hear that audio file once, so you don't want it loaded to RA$$anonymous$$ during a whole scene / level.

Long tracks (30seconds plus) like long music and ambience tracks should always be streamed from a compressed audio file. ('stream from disk' as a load setting).

Unfortunately If you want to loop music seamlessly, it becomes a bit more difficult as decompression can cause problems with instant looping.

avatar image VedSarkar · Sep 17, 2016 at 08:55 AM 0
Share

Hello i am facing the same issue but the difference is that the sound delay is cause in android device and not in unity Play mode in computer. I am using .wav file as an audio source but Load into memory is still not available

avatar image
2

Answer by Trys10Studios · Jan 16, 2016 at 06:51 PM

Compressing the audio via script was my issue. The GetComponent().Play(); in Unity 5 where the () is the sample rate, the example in the unity.docs. scripting is 44100, this leads to latency as the audio is apparently being compressed on the fly, which creates a delay. I noticed that when I doubled the rate to 96000 it literally doubled the latency. Using no sample rate got rid of my delay. Hope this helps anyone that runs into a similar problem.

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

18 People are following this question.

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

Related Questions

How to play an audio one shot clip on a collision 1 Answer

On Collision, Play Sound If Button Is Pressed 1 Answer

help sound on collision when key down 2 Answers

Audio Loops? 1 Answer

Audio not playing on collision 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