Can't get AudioStreamPlayer2D to work

Godot Version

4.7.stable

Question

So there’s this slime enemy that I’ve set up so that it should make a squelch sound when it jumps. The enemy’s scene also has an AudioStreamPlayer2D for this where it’s called like this.

func _on_timer_timeout() -> void:
	if is_on_floor():
		jump_ready=true
		timer.start()
		jump_start.play()

where the timer is how often it jumps and the actual jumping is done if the main _process function loop if the jump_ready bool is true but if I move the sound code to where the actual jump happens it still doesn’t play.

func _process(delta: float) -> void:
	if global.running:
		if not is_on_floor():
			velocity.y += GRAVITY * delta
			if !hit:
				velocity.x = SPEED * direction
		else:
			velocity.x = 0
			hit = false
		if found:
			destination=target.position
			if jump_ready:
				jump_start.play()
				if frog.position.x>destination.x:
					direction = -1
				else:
					direction = 1
				jump_ready = false
				velocity.y = JUMP_SPEED

I’m all the more confused as in the base scene for my game there are two AudioStreamPlayer2D’s that do work, one for the intro to the looping background track and the looping track. The preamble one is called in the _ready function(of the ui node’s script for some reason, idk)

func _ready() -> void:
	music_start.play()

and the other uses signals of the first one ending and itself ending to loop itself.

func _on_music_start_finished() -> void:
	main_music.play()
func _on_main_music_finished() -> void:
	main_music.play()

all of this works fine and makes sense. They also have their bus set to their own music bus.

The enemy’s sound is set to play on an separate sfx bus. The audio file plays in the editor. I tried a whole bunch of different sound formats, I tried adding a sound listener to the player(I didn’t have one before but the music would still play despite them both being the 2d AudioStream variant).

It works with a regular AudioStreamPlayer which I actually found out when trying to make this post which is progress and could still work but I still don’t get why it isn’t working.

I also only added the AudioListener2D very recently and from my understanding that should have fixed things unless I did that wrong.

I’ve got an AudioListener2D in my player scene and the following in the player script

func _ready() -> void:
	listener.make_current()

The whole project is up on my github if I haven’t explained things enough or you need more information(the enemy is referred to as frog(it’s a slime though) because I thought it was funny but fyi there’s that discrepancy).

Hey @throwablebrick . I downloaded your code. You forgot to mention your scene is running in a Subviewport. Go to your SubViewport node, in the inspector you will see a section called “Audio Listener”. Check “Enable 2D” and it should work.

Thank you so much!!! I wasn’t sure if it was relevant so thank you for looking through my code. It does indeed work now.

No problem. I see my comment about the viewport might come across as snarky, but that was not my intention :grinning_face_with_smiling_eyes: . It’s an easy thing to forget. If you ever come across issues with sounds, input handling or world environment, that’s a good place to start investigating, because it overrides/isolates some configurations from the main viewport.

It didn’t come across that way, you’re all good. Good to know for the future, thanks.