Godot 4 dev notes
Collection of tips found while making games with the Godot 4 game engine
These may not be the best solutions ever, but these are just the ones that worked for me
Non overlapping multiple sounds
To play sounds that never overlap even when multiple are played at fast rate do this:
- Put an AudioStreamPlayer in the root of the project, call it
sfx
. All sounds will start from here. - Preload the sound as already suggested
var pling := preload("res://sounds/pling.ogg")
- In an autoload script put this to init the audio player
var player var playback func _ready(): player = get_node("sfx") player.stream = AudioStreamPolyphonic.new() player.play() playback = player.get_stream_playback() as AudioStreamPlaybackPolyphonic
- In the same script define this function
func play_sound(sound_data): playback.play_stream(sound_data)
- Use this whenever you want to play the preloaded 'pling' sound:
play_sound(pling)