AudioStreamPlayer ignores timer, plays repeatedly until it finishes

Godot Version



I’m trying to make an AudioStreamPlayer play a sound repeatedly with a slight delay between each sound. I have it set up so that it should theoretically pick a sound, play it, wait for it to finish, then repeat until it’s done it enough times. Instead it plays it seemingly every frame, with no clear regard for the timer.

Here’s the code I have right now:

if > health_prev_frame:
		for i in ( - health_prev_frame):
			$ = load("res://sounds/Heal" + str((randi() % 3) + 1) + ".wav")
			#await $AudioStreamPlayer.finished
			await get_tree().create_timer(($

I assume this code is part of your _process function? If so, it’s run every frame – and nothing stops play() from restarting the stream every time!

Use $AudioStreamPlayer.playing to check if it’s “safe” to call play.

1 Like