Accessing scene sounds

Hello!

I’m having some trouble getting all sounds attached to a scene. When calling scene.sounds, I get an empty array. When calling a single sound directly using scene.getSoundByName(), the expected <Sound> object is returned.

Am I using scene.sounds properly? Is there another (better) way to get all the sounds in a scene?

Please see lines 24-27 in this playground example:
https://www.babylonjs-playground.com/#PCY1J#82

Thanks for your help! This forum is awesome, btw :slight_smile:

1 Like

Hi, maybe you found this link to the docs:

https://doc.babylonjs.com/how_to/playing_sounds_and_music

Honestly, what I do, is go through it from the top to bottom.

For scene.sounds… it looks like it was introduced after the docs above.

Maybe it has a separate doc somewhere. Might be in the release notes.

A PG search is usually the best way to find examples.

https://doc.babylonjs.com/playground/?code=.sounds

Welcome to the forum.

:eagle: : )

Hi/ you can get access to your sounds from scene.mainSoundTrack.soundCollection
since now you add sounds just to the stage, they fall into the main tracks array? what are you trying to do?

2 Likes

@kvasss: Your solution is what I’m looking for - thank you! (To answer your question, I’m trying to get all the sounds in a scene and dispose() them before loading another set of sounds. Please let me know if there is a smarter way to go about this).

@aFalcon: I’m just using the docs off of https://doc.babylonjs.com, but I don’t see any versioning to indicate that a property like scene.sounds isn’t available in the current version. Is there another set of docs I should be referencing instead?

Also, I’ve got a novice question about the playground search. When I search for “.sounds”, I get results that include “sound” (e.g. BABYLON.Sound()). Is there a way to do an exact search? (Tried quotes but no results were returned.)

Thanks for your help!

1 Like