Godot Version
4.4 Release
Question
I am trying to create a Sound Autoload in Godot 4.4. In my plugin.gd
I’m running:
@tool
extends EditorPlugin
const AUTOLOAD_SOUND = "Sound"
func _enter_tree() -> void:
var audio_bus_layout: AudioBusLayout = load("res://addons/dragonforge_dev_sound/resources/res://addons/dragonforge_dev_sound/utilties/sound/sound.tscn")
AudioServer.set_bus_layout(audio_bus_layout)
add_autoload_singleton(AUTOLOAD_SOUND, "res://addons/dragonforge_dev_sound/utilties/sound/sound.tscn")
add_custom_type("Song", "Resource", preload("res://addons/dragonforge_dev_sound/resources/song.gd"), preload("res://addons/dragonforge_dev_sound/assets/icons/music-library.png"))
func _exit_tree() -> void:
var audio_bus_layout: AudioBusLayout = load("res://addons/dragonforge_dev_sound/resources/default_audio_bus_layout.tres")
AudioServer.set_bus_layout(audio_bus_layout)
remove_autoload_singleton(AUTOLOAD_SOUND)
remove_custom_type("Song")
(In my repo you’ll see I also tried manually adding buses, and I’ve got some debugging going.)
When I run:
for index in AudioServer.bus_count:
print(AudioServer.get_bus_name(index))
AFTER I load the buses, I get:
Master
Music
SFX
Ambient
UI
Dialogue
I also get tat in the exit before I load back the default (which only contains the MASTER bus.)
But when I play()
a sound in sound.gd
none of the buses exist. I added a test UI scene and when I press the button to play the default click sound, which should come out of the UI bus, I get an error saying that bus doesn’t exist. The sound plays from the Master bus instead.
Things I have tried:
- Manually adding all the buses myself.
var bus_list: Array[String] = [
"Music",
"SFX",
"Ambient",
"UI",
"Dialogue"
]
for bus_name in bus_list:
if AudioServer.get_bus_index(bus_name) == -1:
var new_bus_number = AudioServer.bus_count
AudioServer.add_bus(new_bus_number)
AudioServer.set_bus_name(new_bus_number, bus_name)
print("Adding bus %s: %s" % [new_bus_number, bus_name])
- Using the UI to load the bus layout.
- Reloading the project after loading the plugin.
- Banging my head against my desk.
I am open to suggestions.
Code
The full project (which is quite small) is here: GitHub - dragonforge-dev/dragonforge-sound The other related discussion I posted on this topic is here: Best way to make an Expiration Timer for Temporary Objects (just people don’t waste their time commenting on my commented out - not yet deleted - code).
@gertkeno and @hexgrid I’m not sure if either of you have any ideas on this one.