AudioMaster
September 15, 2022

Audio playback in Godot is relatively easy. Basically we add an AudioStreamPlayer node, assign an audio resource then, when desired, we call the play() function within the node instance. Yet, often we need to take care about the node lifetime.

As an example, consider a scene meant to be used a pickup. In this scene an audio stream player node is added in order to playback a sound effect whenever the player picks that object. Within the code we call the play() function at that moment then destroy the pickup instance. The playback, if it starts at all, will most likely not finish. The reason is that the destruction of the pickup object also removes the stream player node from the tree.

And how about fade-in, fade-out or even cross fading effects? While those are not exactly hard to code, depending on how the audio stream player nodes are distributed around the project it might become a little problematic to perform this kind of fading.

So, this addon's goal is aimed at solving those problems.

Before delving into how to use this addon, there is one important thing I wanted to mention, which I have noticed while testing the system. This is unrelated to the script in this addon. Using AudioStreamPlayer2D and AudioStreamPlayer3D to playback OGG files resulted in random "pops" instead of the desired sound effect, while sometimes the "pop" came slightly after starting the playback of the sound effect. I didn't notice any problems with "WAV" playback on those two types of nodes. With the AudioStreamPlayer I didn't notice any problems with either OGG or WAV.

Happy forging!

Introduction
Previous12345678
9
10Next