Efficient ways to handle Sounds at Runtime?

I’ve been looking into how to better handle sounds within my game, which is going to be multiplayer and quite heavy on sounds. There doesn’t appear to be any concise answers as to the best way to handle sounds during runtime, but I have found some useful forum posts that specify more efficient methods.

  • Serialising the sound data and creating the sound instances during runtime as needed.

  • Storing the sounds where they’re needed and using PreloadAsync() so there’s no delay on playing the audio.

  • Using a ModuleScript in ReplicatedStorage to handle sound playback on both client and server.

Whilst these are all efficient, I’m unsure what the best way to handle everything in one would be. It seems less efficient to create new instances for small sounds played often, and preloading a bunch of small sounds often also doesn’t seem the most efficient use of server memory.

My current idea would be:

  • Keep small client sounds such as UI/SFX that are played often in the location they’ll be played from so they’re always loaded.
  • Any larger audio like music tracks is serialised and stored in a ModuleScript in ReplicatedStorage so both the client and server can access it, and then preloaded prior to being played.

Is this the right way to approach this topic, or is there a more efficient way to be handling audio during runtime?

Extra: I also plan to have creatures and other assets that are replicated often. What’s the best way to handle each instance also needing its own audio?

In case it helps anyone else, here are the links to the other forum posts that explain their methods in greater detail:

I’d say your approach is very solid. There are a few key things that are important to remember:

  1. Assuming Roblox works the way I think it does, the server doesn’t actually need to load audio. There’s no person on the server that can hear audio. All the server sees is the string that contains a reference to the audio that is stored in the Roblox cloud. Only clients will actually (down)load the audio data, so it’s fair to assume that audio will have a negligible impact on server memory.

  2. For clients it’s most important to stay within the “budget” of memory that a client has. Mobile phones are usually the most limiting factor as the cheapest modern phones have roughly 1-2GB of memory. According to the files on my own PC, music files can be multiple MBs in size, while audio effects are usually less than 100KB. With this in mind you can safely load and play dozens of songs and still have enough space left to load your game’s images, interfaces, code, and so on. But if your game is heavy on music, it would be smart to take precautions.

  3. Although I’m not 100% sure, I believe that sound instances themselves take up almost no memory. Only once you play a sound instance will Roblox fetch the data from the cloud, store it in your memory and play it (which is why the first time you play music there’s sometimes a delay). So whether you have a folder with a 100 sound instances or a ModuleScript with 100 id strings is up to personal preference.

There are still a couple unknowns that I haven’t found any documentation for. For example what happens when you start running out of memory? Does Roblox automatically wipe audio data from memory that hasn’t been played in a while?

That said, I think your approach strikes a good balance between convenience and performance. Keep cheap sound effects loaded for quick response times and flexibility, and only load music when it’s needed.

1 Like