Hi,
I created an Audio Manager, extending from Node, containing many AudioStreamPlayers as childrens, each AudioStreamPlayer dedicated to a sound fx (a wav file) or a music playlist (see screencopy). When I use this AudioManager as a a child of my main game scene, everything works fine and I can trigger sounds at will.
But I’d like to use this AudioManager as a singleton, in order to avoid duplicates and also sound or music chops between scene changes.
As soon as I install this AudioManager as a singleton, when the program runs, it seems that every AudioStreamPlayer “forgets” about its declared AudioStream resource. When debugging, I see that every AudioStream field of every AudioStreamPlayer is empty… Why does it lose this resource ???
In general, is it normal that a Scene instanced as a singleton looses its resources ?
I did something like this by adding a global script I called PlaySound, so I can call functions on it like cannon_shot(). That lets me call PlaySound.cannon_shot() from anywhere in the code.
I’ve also got a more complex function in there for setting up positional sounds; those you need to spawn individual per-sound nodes and place them in the scene tree to make positional audio work, so I’ve left that out for simplicity.