Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How can I prevent Audioclips to decrease performance

Discussion in 'Audio & Video' started by mfatihbarut, Jan 17, 2021.

  1. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,058
    Hi all,
    I use some sounds like machine gun and monster hurt sounds in my scene and I am afraid if I don't manage correctly created sounds may invade RAM too much and/or make CPU busy (because of garbage collection and like that)
    How can I handle audio clips in a good way?
    Forexample I tried Master Audio package which is very sofisticated one but still it seems it doesn't prevent performance issues.

    What can I do, is there any well known pooling process for audioclips or just using audiosource.playoneshot() may solve all of my problems?
     
  2. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    You can have a single machine gun sfx object and a single monster sfx object with Audiosources. Then when you need them just relocate them and use playoneshot().

    In addition you can change the audio distance volume profile to reduce the range and limit the sources as well as lowering the priority of the audiosources (this can ensure player audio has priority and is always played).

    You could also use distance from player to adjust priority.
     
  3. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    2,198
    Use a mixer.
     
  4. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    390
    Hi. Do you actually have examples of where audio has been an issue for performance? My wip game uses master audio as well. I have about 300 sound effects, background music and a small number of effects e.g. reverb and audio performance is not an issue. I am developing for pc platform so perhaps on mobile this would be different.
     
  5. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,124
    Profile. If it isn't a problem you're just making additional work for yourself for no benefit and if you do this often enough you will never finish anything.

     
  6. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,058
    good to know but how?
     
  7. willemsenzo

    willemsenzo

    Joined:
    Nov 15, 2012
    Posts:
    585
    General rule of thumb is to stream any large files from disk (such as music) and other small sound files like gunshots etc. directly from RAM. This will make a big difference in memory use because large files don't have to be entirely put into memory but rather read in small chunks from your harddrive.