According to documentation (API and manual):
“A sound will continue to play even if the game object the sound component belonged to is deleted. You can call sound.stop() to stop the sound (see below)”
Below is sound.stop(“go#sound”)
But, I got error:
ERROR:GAMEOBJECT: Instance ‘/go’ could not be found when dispatching message ‘stop_sound’ sent from board_5x5:/go#board_script
Using url leads to different error related to invalid hash after go was deleted.
Why I want to stop (and operate) sound after deleting a game object?
In my game I have game object stars, spawning and flying with looped sound of sparkles (and changing panning in update to hear stars flying from left to right etc). I can’t abruptly stop looped sound (because of harsh click) and need to fade out it. So, when star reached target, I start impact particles, stop sparkle particles, delete go and want to start fading out looped sound.
To avoid suggestions to have separate soundManager with all sounds inside to manage sounds separately. Actually, I have this with all great features as gating etc. But, let’s say, you spawned 5 stars at similar time. Then you have 5 voices for the same sound in manager. You can stop sound on separate voice like this sound.stop(“#sound”, {play_id = id}) but you can’t manipulate pan and gain for separate voices unfortunately. go.set(“#sound”, “gain”, 0.2, {play_id = id}) sets gain to all voices at once (and for all future plays for some reason, like there is hidden sound group for all voices).
Just abruptly stopping voice is useless because it usually generates clicks. I need fade out. I need to change pan on the fly.