Coroutine usage issue

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By FelicePollano

Please have a look at my teleporter code:

func _process(delta: float) -> void:
	if (player.transform.origin-transform.origin).length_squared()<20:
		if not $AudioStreamPlayer.playing:

notice the commented #yield, if i left it it apparently hangs. What I’ve tried is to play the sound and then when finished I wan to to change scene. I think issue can be related with having the yield in the process, and had call to set_process(false) but not sure, not sure how coroutine works in this case

I tried to replicate your setup but it works fine (Godot 3.5.1), have you changed any of the properties of the AudioStreamPlayer or tried with a different audio file / stream? And does it crash if you connect the finished signal to a separate function and run the scene change there?

a_world_of_madness | 2023-01-08 20:06

:bust_in_silhouette: Reply From: Inces

Hehe it is beacause You yield every frame when the music is playing, so when “finished” is emitted, it only unyields one stack, while process still awaits millions of them byt that point :slight_smile:

You can just indent your yield and change_scene one tab to the right to fix it