I have been trying to play sounds in my game for a week, and cant get any result. If I assign the audio file directly to the AudioStreamPlayer2D in the editor, it works. But, if I try to load the audio clip and assign it on code, I dont get any sounds. This is my code:
var CorrectSound = preload("res://Sounds/sfxsoundsfanfare3.wav")
func _process(delta: float) -> void:
$AudioStreamPlayer2D.stream = CorrectSound
$AudioStreamPlayer2D.play()
I have tried load instead of preload. I have tried moving the code to another script. I tried with export, then assigning the value in the editor, and nothing. So, I guess Im not doing it the right way. Whats my error here?