The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+1 vote

Hi is there a way to listen to a sound finishing playing?, and then executing a callback?. I was looking for some signal to connect to, but i couldn't find it.

If there isn't would doing something like this be good?

var started_playing
var last_sound

func _ready():
   started_playing = false;
   MySampler.add_user_signal("sound_finished", [{"sound": TYPE_STRING}]);
   set_process(true);

func play_sound(key):
   MySampler.play(key);
   started_playing = true;
   last_sound = key;

func _process(delta):
   if(!MySampler.is_active() && started_playing):
      emit("sound_finished", last_sound);
      started_playing = false;

Might have some syntax errors couse i wrote it directly here, but asking if the generla idea es correct and any who has experience in this feel free to advise me, thanks!.

in Engine by (30 points)

1 Answer

+1 vote
Best answer

Hi, i used the code and it works perfectly.

I had to add a timer with a wait time of 0.2 to support the case where you fire a sound immediately after one has finished, which is pretty rare in my game but wanted to have that working nonetheless. This is the final version i'm using:

Node Code
And this is a client using this enchcanced SamplePlayer, it starts to repro "sound2" after "sound1" finishes.

Client
Made this repo with my sandbox for testing this if you want to download it feel free to do so. Happy Coding! :-)

by (30 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.