🤖 Switching Sound Resources by Script in Godot3

Switching Sound Resources by Script in Godot3

This article explains how to switch between and play multiple sound resources (music and sound effect files) with a single “AudioStreamPlayer” node. Basically, only one sound resource can be set per “AudioStreamPlayer” node. In other words, you must add “AudioStreamPlayer” nodes in the scene tree for each sound resource. You may feel useless in a situation where there are multiple nodes in the scene tree with the same settings except for the sound resource (as shown in the screenshot below), and you may also feel a little uncomfortable with the lack of visibility in the scene dock. So, if you have multiple sound resources that are never played simultaneously (e.g., multiple sound effects for different types of character attacks, multiple sound effects for different types of buttons on the UI, etc.), add only the minimum necessary “AudioStreamPlayer” node for each use to your scene. If you code a program that switches sound resources according to the situation, there will be no waste and the scene dock will look cleaner. In this tutorial, we will prepare only one “AudioStreamPlayer” node and...

2022-10-19 · 3 min