That’s not the problem. Babylon should simply enable sound inside a user interaction by default, rather than showing an unmute button and requiring users to press it. (Imagine if every game you ever played always started muted by default, that’s not the experience users expect).
The solution so you can get rid of the unmute button once and for all is simple in userland (though Babylon should just do it by default!):
// make your scene, as usual:
const engine = new BABYLON.Engine(canvas, true);
const scene = new BABYLON.Scene(engine);
// create any auto-playing sounds here (f.e. music)
const autoplayingSound = new BABYLON.Sound()
// But *BEFORE* you do anything else, add this:
document.body.addEventListener('pointerdown', () => {
// THIS! This has to run *before* you call .play() on ANY sound.
// This unlocks all sounds, and the unmute button will not appear. Yay!
BABYLON.Engine.audioEngine?.unlock()
// start auto-playing sounds
autoplayingSound.play()
}, { once: true });
// Continue as before, add your scene.onPointerWhatever handlers, play sounds in those handlers, etc.
scene.onPointerUp = () => {
someClickSound.play()
}
Babylon should just do this by default, and it can additionally provide the button to mute/unmute (rather than just unmute). It would make a lot of sense to users that way.