My sound questions and issues

Since I am a bit ignorant when it comes to the sound object, I thought I should make a post about what I want to achieve, and ask how best to go about it.

I have a large world, and I want to have many different sounds playing, at specific locations. Fireplaces will have a crackling burning sound, waves crashing by the shores, birds or monkeys in the jungle trees, wind when on top of mountains, dripping in caves and the splash of waterfalls, just to name a few.

I do not want to have all of these sounds force loaded into memory on the client.

So my thought was to have the client only load and play a sound when you are near it, however this brings up a question. How does Roblox handle the memory of sound loading on clients.

If I have a sever sound object, and it replicates, will it always be in client memory? What if the server sound object is destroyed? Will that remove it form client memeory, if there are no other active references to that sound file? What if a sound id is changed, will the previous one be unloaded from memory?

I could not find anything answering these questions, so I created a system where the sound object is only created on the client, when a player is near it, and is destroyed when out of range, however with this I loose any 3D sound effects.

So should I do the same thing, but on the server end? Should I create and destroy sound objects as players get near them? Although if Player A is in the cave at one side of the map, and player B is at the beach on the other side of the map, would both clients have cave and beach sound loaded in memory? or would only the client that is capable of hearing the sound (emmittersize, and maxrange) actually get the sound data? And when destroying sound objects for one player (from server) clear the memory for that sound from its client?

How does the client know when to remove sounds from its memeory, and is it already very managed, or are there things a developer can do to affect this?

I know its a lot to read and a lot of questions, but I thank you for the time to look this over and any advice or knowledge you have is appreciated. Thank you.

1 Like

If you look at the wiki page for ContentProvider, you could find a method called PreloadAsync. According to the page, sounds are loaded into memory by asset ID. That way, if you’re planning to utilise five different sources that play the same sound, only one audio file would have to be loaded. There isn’t much information on how that memory is managed. However, I’ve noticed that if you use a large amount of decals in a game and set one the the decals’ transparency to 1 then set it again to 0, it rə-loads the decal into memory.

Thank you for the information, especially about the reloading decal. That’s at least a clue as to how efficient the client’s memory management seems to be… for decals at least.

Sounds should work in much the same way, given that they’re loaded similarly to how decals are.