+1 vote

How do i play multiple sounds in quick succession without one overlapping the other?
i have a global sfx player but it has only 1 AudioStreamPlayer. I searched the internet and found polyphony but it is only for godot 2. is there something similar to polyphony for godot 3?

in Engine by (20 points)

2 Answers

–1 vote

One way of doing it would be to add a [signal][1] for the finished event, ex:

func _on_AudioStreamPlayer_finished():
    print( "Audio finished, start the next one logic")
    #your logic to play the next one or a random one here...
    pass

Hope this helps :-)

by (895 points)
+6 votes

To enable polyphony for AudioStreamPlayers I have added the following script:

    #helper for multiple audio stream playback
    extends AudioStreamPlayer2D

   func play( from_position=0.0 ):
        if !playing:
            .play(from_position)
        else:
            var asp = self.duplicate(DUPLICATE_USE_INSTANCING)
            get_parent().add_child(asp)
            asp.stream = stream
            asp.play()
            yield(asp, "finished")
            asp.queue_free()

It uses polymorphism to override the AudioStreams play()-function and instantiate a new player. This also works for audio tracks in the AnimationPlayer.

by (199 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.