UniqueID for sound?

Hey, is there a uniqueID for sound like there is for mesh? or some other unique identifier that can be used to retrieve it?

I dont’ know but may I just ask why not just by name? I would understand by ID but what will a uniqueID add to it? If you want by ID (i.e. playing a same sample depending on context), I suppose you could just attach it to a mesh/node and set an ID to this, no?

cc @RaananW but I think they do only have a name

no, the sound class in babylon doesn’t have an id. Since it is javascript you can add one yourself on runtime, or explain why you need one and we will be happy to consider adding one to the sound object :slight_smile:

1 Like

I’m working on an application where I’m adding sounds, videos, audio, and models via URL, and the name will be set via the user so chances are it won’t be unique.

Now everything else can be added as a 3d model so manipulating it can be done easily via unique ids except sounds.
It is entirely possible I set the name myself and use it as a uniqueID but if there were a uniqueID present it would make the whole flow more uniform.

What @mawa suggested would work but it won’t remove the sound from the scene if you delete the mesh to remove the sound you will need reference to the sound object itself.

Overall I believe everything that’s added into the scene should have a uniqueID so it is simple to look it up as names get overwritten if a new object of that name is added

Thanks for the details.
You know, it kind of makes sense but it might not be just that easy to implement.
Just wanted to let you know that I believe @RaananW will have some well deserved holidays from this week (as far as I know). May be @sebavan can study your case, but I don’t know. Do you believe that for a moment you could work out other parts of the project. Else, you might need to find some temporary go-around.

Highly appreciate the quick response, I understand it might take a while to implement this, I can go with a workaround for now but if this gets implemented it will streamline the whole process! Thanks a lot!

Hi @EmberCult :slight_smile:
I am still here till wednesday.

So - there is no isue adding a uniqueId to sounds. What i meant was that you can do it yourself if you directly use javascript. If you use typescript there might be an issue with the typing TBH.
if you add this line after every call to the sound constructor, you will have a uniqueId to every sound:

const sound = new Sound(.....);
sound.uniqueId = scene.getUniqueId();

The reason I am not 100% happy to add it to the sound class is the fact that we are planning a revamp of our audio engine very soon, and I don’t want to add more complexity before we start the work ( Audio Engine V2 · Issue #12576 · BabylonJS/Babylon.js (github.com))


:yum: :smiley:

Thanks, I just added
this.uniqueID = scene.getUniqueId()
in sound.js and also added type in sound.d.ts

After that made a function to iterate over all the sounds and check uniqueID and it’s working flawlessly!
Thanks a lot for that insight!


I saw this on GITHub. It is good news to upgrade the audio system.


Ce forum est en anglais; on m’a déjà fait la remarque :wink:
And then I agree that this is good news indeed :smiley:

lol, Yes. it’s because I quoted with the page translated into French.
Afterwards he happens to explain to me in French with Deltakosh, when I couldn’t do it in English. But this is still very rare.