Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by Reasqn · Jul 19, 2017 at 02:27 PM · audiosoundaudiosourcelagplay

[NoBraves] Sound makes lag

Hello everyone. I am making an explorer game with a procedurally generated terrain and some animal AI in the world. Yesterday I made my sound API for the game with some usefull methods etc. The problems is that the sound decreases a LOT the fps. Without ths sound the game has around 100 FPS and as soon as I toggle them, My game has around 20 FPS. I display sounds by spawning an empty GameObject a a given point and make him .Play() the clip. I destroy the gameObject once the sound is finished. I allready made some optimization by only playing the sound if the distance between the player and the sound is less than the max distance but it still lags.

Here is a great example of the code I've done

     public enum Parameter { LOOP, TWO_DIMENTIONAL,  }
 
     public static AudioSource Source(GameObject holder) {
         return holder.AddComponent<AudioSource>();
     }
 
     public static AudioClip Play(SoundEffect sound, Vector3 position) { return Play (sound, new Sound.Parameter[0], position); }
     public static AudioClip Play(SoundEffect sound, Sound.Parameter[] param, Vector3 position) {
         if (sound.clips.Length == 0 || GameSettings.sqrtDistance3D (PlayerController.instance.transform.position, position) > (sound.maxDistance + 4f * sound.clips[0].length)*(sound.maxDistance + 4f * sound.clips[0].length)) return null;
         List<Sound.Parameter> parameters = new List<Sound.Parameter> (param);
         GameObject soundPlayer = new GameObject ("SoundEffect " + sound.clips[0].name);
         soundPlayer.transform.position = position;
         AudioSource source = Source (soundPlayer);
         source.volume = sound.volume;
         source.maxDistance = sound.maxDistance;
         source.loop = (parameters.Contains (Parameter.LOOP));
         source.spatialBlend = (parameters.Contains(Parameter.TWO_DIMENTIONAL)) ? 0f : 1.0f;
         AudioClip clip = sound.clips [Random.Range (0, sound.clips.Length)];
         source.clip = clip;
         source.Play ();
         if (!source.loop) GameObject.Destroy (source, clip.length);
         return clip;
         return null;
     }

So I really don't know why it does that, maybe I have too much sound effects in my world. For example the footsteps sounds are played each 0.3 second for each near animal around 30 meters (sometimes I have like 10 animals around me so there is around 30 footsteps sounds per seconds)

Otherwise I generate water sounds on my water by detecting it at the start procedurally. alt text

So If you have anyu ideas of why it decreases so much my fps, please answer this unity question, It would be really great ! If you want to see any code just ask I will provide it, there is actually a lot of code so I can't post everything here. Thank you very much for listening at this, I hope one of you has the answer !

       Julien, Head of the NoBraves Studio channel.
soundspng.png (462.2 kB)
Comment
Add comment · Show 1
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 Reasqn · Jul 20, 2017 at 10:08 AM 0
Share

up up up up

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Reasqn · Jul 19, 2017 at 02:32 PM

Here is a gread example of sounds in the world alt text


soundexample.png (268.2 kB)
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

86 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 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 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 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 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

Realistic Sound Effect 0 Answers

Background Music 2 Answers

Is there a way to create a random Audiosource loop? 2 Answers

Audio not playing... 2 Answers

Audio in WEBGL on IOS devices -1 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