Audio Source GameObjects With Object Pooling?

Hey everyone.
Quick question (or a general wonder), I need to use Audio sources for my game (3D), and I was asking myself which approach will be the best.
Here’s the thing, let’s say I have an “eating” sound whenever the player eats food, and there are 30 players in the game, so any moment another player can eat food. The sound is a Gameobject with an audio source and needs to be at the position of the eating player head. But, as I was saying earlier, what if every moment someone is eating, how do I use that eating game object that needs to be positioned the eating player’s head? Should I use pooling so every time a player eats, it will spawn a new Audio source game object at the player’s head position, and after he’s done I will disable it and wait for the next player to eat? Is that the appropriate approach for this kind of situation?

I’m sure you will be the best answers I could find Unity fellows.
Matan

Hey there!

Your “Idea” is the best bet, use a Pooling System where you can ask for AudioSources,

everytime you ask for an AudioSource, pass the Position and some “Settings” to the AudioSource, for example “Volume Strength” etc. you might want to have different Settings for different Sound effects :slight_smile:

Small Edit: Also pass the Audio Clip you want to play :wink:

1 Like

Great. Thanks Terraya!