• 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 /
  • Help Room /
avatar image
0
Question by Batka · Nov 22, 2016 at 12:21 PM · audiolagaudio files

I can't solve the audio lag problem, I tried all I could.

Hi,

I tried everything, and I can't seem to figure out the problem with why is my audio lagging.

The audio needs to be played in the same moment when the player destroys a particular object. Here is the code that does this:

     void OnTriggerEnter2D(Collider2D col)
             {
                string tag = col.gameObject.tag;
                //this plays the audio, will get into it as well
                AudioManager.Instance.SoundFx(tag);
                //This destroys the gameObject, so SoundFX() is called before it
                OnHitResponse(col.gameObject);
              }

Now, lets take a look inside AudioManager.SoundFx method:

 public void SoundFx(string tag)
         {
             switch(tag)
             {
                 case "Normal":
                 case "Hard":
                 case "Transparent":
                     LadderPlay(hitsQTY, tag);
                     //I am recording hits Quantity to know which note to play
                     hitsQTY++;
                     break;
                 case "NotDisappear":
                     PlayOneShot(notDisappear);
                     break;
                 case "PortalA":
                 case "PortalB":
                     PlayOneShot(portal);
                     break;
                 case "Death":
                     PlayOneShot(death);
                     break;
             }
         }

And here is the LadderPlay method, part of AudioManager class:

 public void LadderPlay(int k, string tag)
         {
             // Both triangle and harp sounds will be played with ladder effect
             string type = (tag.Equals("Transparent")) ? "Triangle" : "Harp";
             // Directory that holds the Triangle and Harp sound effects
             AudioClip[] currentDict = audioDict[type];
             if (PlayerPrefsX.GetBool(Constants.PrefsIsSoundOn))
             {
                 if (k > currentDict.Length - 1)
                     k = currentDict.Length - 1;
                 audioSource.PlayOneShot(currentDict[k], sfxVolume);
             }
         }



That's the whole code that is called when the audio needs to be played.

Now please, let me tell you all I've tried so far:

  1. I used profiler to determine that 'OnHitResponse' (called after the AudioManager.SoundFX() method), is making my game fall to 30 FPS. I fixed that, without fixing the audio lag (but hey, my game now runs smoothly on 100fps, no matter when).

  2. I noticed I have .mp3 files, so I changed that immediately, re-creating the sounds in .wav format.

  3. I changed the AudioSettings lag settings to - Best Latency (this made my sound FX to have some white noises while playing them, and it seemed that the lag has gone. But when I tried the game on my Android, the lag returned, and the white noise DISAPPEARED.

  4. I triple checked that the sound waves in the FX files start from t0 (first second).

Any ideas guys and gals?

I am stuck on this for a week, and I fear that the solution will be something really simple. Thanks a lot for your time, it will save mine significantly. :)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by tanoshimi · Nov 22, 2016 at 12:24 PM

And have you set to preload audio data and decompress on load? https://docs.unity3d.com/Manual/class-AudioClip.html

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 Batka · Nov 22, 2016 at 01:07 PM 0
Share

I just did that, but no success:

Just in case, is this the new wording for preload audio data:

http://prntscr.com/dadng2

Ah I saw it, it's still preload audio data, but anyway I've already done that in the past

avatar image
0

Answer by zakirshikhli · Dec 29, 2019 at 04:41 PM

Try my tips from this question AudioSource.Play lags.

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Music drags / lags while loading things 1 Answer

Switching Audio snapshots on button press 0 Answers

Audio not playing when destroying a GameObject. 1 Answer

Troubleshooting Footstep Audio 0 Answers

Playing audio when the user is dancing / moving a VR (GEAR) Controller 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