Any reason not to provide auto-panning for sound components?

Sounds already have to be specified via sound components. Sound components must be attached to some game object. Game objects have transforms. So every sound in a game already has a position. Is there any reason not to provide a property on a sound component like “positional” that’s a normalized 0-1, with 1 meaning 100% positional panning and 0 meaning none (current behavior)?

This came to mind as I’m writing some scripts/game objects to encapsulate this same idea… what Defold already has is so close to being useful out of the box, with all of the data and properties and capabilities… just no option on the sound component to turn it on.

Hi,

Personally I dont think it would be so usefull, because the game object you attach the sound component on, is not necessarily the game object having the position data.
I prefer to handle sounds in a centralized maner, putting all sounds in a collection, with a sound manager script which handles sound playing via events.

So the game object send an event “play sound 1” with its position as event data, then the sound controller compute the good panning based on that. Because if you want kind of “3d sound” or “positionnal sound sources” you also have to take distance from the player into account and, maybe also the speed and direction of source and change or animate the gain also.

So you will much never have a one-to-one mapping between position of the outline game object and sound panning… so making an auto-pan function is really subjective task..and will feel kind of a toy feature in the best case.

Just my opinion by the way :slightly_smiling_face:

2 Likes

Interesting, and totally valid if non-toy projects are expected to evolve a sound manager sort of inevitably. Is that the best / idiomatic practice?

If so, maybe I should move to it - but I’m curious what the benefit is of making a global dependency that anything with sound must coordinate with (rather than including sounds as an “output side effect” of the simulation of a particular entity, much like animated sprites are). I’m setting up a robust set of non trivial sounds for the first time in Defold now, so I don’t have informed opinions about it yet.

1 Like

In my point of view the sound manager is to audio what the render_script is to visuals.
You have sprites, tiles, shaders etc. and things to view, and the role of the render_script is to orchestrate all of it, layer by layer.

The sound manager does this for audio. You must layer many sounds, maybe you need to gate stuff, maybe you want 1 voice effect at a time but have many game objects who wants to talk (like think “walking arround talking PNJs”), you have music, ambiances, player effects etc.

So you need a global system that handle this. So game objects just have to trigger events (I use defold-events lib for these kind of global systems). So the object just ask to play a particular sound, but doesnt need to know where the sound component is, nor how to play it. So it is really not a direct dependency, the inverse actually.
And you can code the events before even wiring reall sound in the game.

Then you can also organise your sounds in different collections/sound banks and load them when necessary (loaded by the sound manager). Think that musics and sound files are heavy, maybe you dont want to load every sounds into memory at start of game.

Finaly, having dedicated collection make it also easier to import many sounds. I use Reaper for audio, and export many files at once. Then I copy it in my project, use an editor script to create all sound components files, then an editor script to insert them directly into a collection. I dont need to find out which game object will use which sound.

And I define a kind of “naming convention” to idenfy sounds ( “{soundbank}{soundname}{soundsequence}” where the sequence is when I have many different versions of same effect, so I can randomize) then I build a lua fil with a table n enumerating all sounds and linking with the actual url to sound component.

So in code you can load this module and reference the sound name with autocompletion, and send it with events to be played.

I dont know if this is the best practice, but it sounds well enough for me

4 Likes

Thanks for detailing your process!

1 Like

We will have to think about positional audio in the future, as more games are using 3D.
But it’s currently not in our immediate planning.

4 Likes