[SOLVED] How to set up a sound managment singleton

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By onlyJB
:warning: Old Version Published before Godot 3 was released.

Got a similar problem as this:
https://forum.godotengine.org/570/how-to-play-audio-whilst-changing-scene

In the thread somebody was able to help in IRC, the solution is not posted there tho.

I try to play sound effects via a singleton, stuffed that singleton .gd script inside of a SamplePlayer node. Even tho it is not showing any error, the “play()” function is not playing the sound.

I did load the sample into the SamplePlayer node, and if i put the node inside of my root ie, it is working proper. A debug print is also showing that the function of the singleton script is called correctly.

extends SamplePlayer

func _ready():
	pass
	
func playSound():
	play("Fireball")
	print("debug SFXmgr")

Thanks in advance,
Jonathan

//edit

I was able to solve the problem with putting the “SamplePlayer” node into a “Node” and using:

SFXmgr.get_node("SamplePlayer").playSound()

to call the function.

:bust_in_silhouette: Reply From: literalcitrus

This may not actually be a solution for you, but I had been in a similar situation a while ago where audio wasn’t playing from a singleton. This was what solved it:

Use self.play() instead of play().

In theory this shouldn’t change anything, but maybe it’ll work for you like it did for me.