From 7f227acb6aa96534f8e99ab3d8238964a5fbd732 Mon Sep 17 00:00:00 2001 From: Daniel Samson <12231216+daniel-samson@users.noreply.github.com> Date: Wed, 29 Apr 2026 15:00:56 +0100 Subject: [PATCH] auto-detect Music/FX bus in editor When a player enters the tree in the editor, if its bus is still the default "Master" and a "Music" (or "FX") bus exists in the AudioServer, switch to that. User-customised buses are not overridden. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/DynamicSoundFXPlayer.gd | 6 +++++- src/DynamicSoundFXPlayer2d.gd | 6 +++++- src/DynamicSoundFXPlayer3d.gd | 6 +++++- src/DynamicSoundPlayer.gd | 6 +++++- src/DynamicSoundPlayer2d.gd | 6 +++++- src/DynamicSoundPlayer3d.gd | 6 +++++- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/DynamicSoundFXPlayer.gd b/src/DynamicSoundFXPlayer.gd index af71ed1..c9151dc 100644 --- a/src/DynamicSoundFXPlayer.gd +++ b/src/DynamicSoundFXPlayer.gd @@ -18,8 +18,12 @@ extends AudioStreamPlayer var _core : DynamicSoundFXPlayerCore; func _enter_tree() -> void: - if Engine.is_editor_hint() and stream == null: + if not Engine.is_editor_hint(): + return; + if stream == null: stream = AudioStreamPolyphonic.new(); + if bus == &"Master" and AudioServer.get_bus_index("FX") != -1: + bus = "FX"; func _ready() -> void: _core = DynamicSoundFXPlayerCore.new(self); diff --git a/src/DynamicSoundFXPlayer2d.gd b/src/DynamicSoundFXPlayer2d.gd index 0ff84e8..71c4447 100644 --- a/src/DynamicSoundFXPlayer2d.gd +++ b/src/DynamicSoundFXPlayer2d.gd @@ -17,8 +17,12 @@ extends AudioStreamPlayer2D var _core : DynamicSoundFXPlayerCore; func _enter_tree() -> void: - if Engine.is_editor_hint() and stream == null: + if not Engine.is_editor_hint(): + return; + if stream == null: stream = AudioStreamPolyphonic.new(); + if bus == &"Master" and AudioServer.get_bus_index("FX") != -1: + bus = "FX"; func _ready() -> void: _core = DynamicSoundFXPlayerCore.new(self); diff --git a/src/DynamicSoundFXPlayer3d.gd b/src/DynamicSoundFXPlayer3d.gd index e21220d..fdd6613 100644 --- a/src/DynamicSoundFXPlayer3d.gd +++ b/src/DynamicSoundFXPlayer3d.gd @@ -17,8 +17,12 @@ extends AudioStreamPlayer3D var _core : DynamicSoundFXPlayerCore; func _enter_tree() -> void: - if Engine.is_editor_hint() and stream == null: + if not Engine.is_editor_hint(): + return; + if stream == null: stream = AudioStreamPolyphonic.new(); + if bus == &"Master" and AudioServer.get_bus_index("FX") != -1: + bus = "FX"; func _ready() -> void: _core = DynamicSoundFXPlayerCore.new(self); diff --git a/src/DynamicSoundPlayer.gd b/src/DynamicSoundPlayer.gd index 827754e..54b7c10 100644 --- a/src/DynamicSoundPlayer.gd +++ b/src/DynamicSoundPlayer.gd @@ -42,8 +42,12 @@ func _set(property: StringName, value: Variant) -> bool: return false; func _enter_tree() -> void: - if Engine.is_editor_hint() and stream == null: + if not Engine.is_editor_hint(): + return; + if stream == null: stream = AudioStreamPolyphonic.new(); + if bus == &"Master" and AudioServer.get_bus_index("Music") != -1: + bus = "Music"; func _validate_property(property: Dictionary) -> void: if property.name in ["RandomMinPitchScale", "RandomMaxPitchScale"]: diff --git a/src/DynamicSoundPlayer2d.gd b/src/DynamicSoundPlayer2d.gd index 61ab21e..e16a155 100644 --- a/src/DynamicSoundPlayer2d.gd +++ b/src/DynamicSoundPlayer2d.gd @@ -41,8 +41,12 @@ func _set(property: StringName, value: Variant) -> bool: return false; func _enter_tree() -> void: - if Engine.is_editor_hint() and stream == null: + if not Engine.is_editor_hint(): + return; + if stream == null: stream = AudioStreamPolyphonic.new(); + if bus == &"Master" and AudioServer.get_bus_index("Music") != -1: + bus = "Music"; func _validate_property(property: Dictionary) -> void: if property.name in ["RandomMinPitchScale", "RandomMaxPitchScale"]: diff --git a/src/DynamicSoundPlayer3d.gd b/src/DynamicSoundPlayer3d.gd index e294db2..4cc5ca7 100644 --- a/src/DynamicSoundPlayer3d.gd +++ b/src/DynamicSoundPlayer3d.gd @@ -41,8 +41,12 @@ func _set(property: StringName, value: Variant) -> bool: return false; func _enter_tree() -> void: - if Engine.is_editor_hint() and stream == null: + if not Engine.is_editor_hint(): + return; + if stream == null: stream = AudioStreamPolyphonic.new(); + if bus == &"Master" and AudioServer.get_bus_index("Music") != -1: + bus = "Music"; func _validate_property(property: Dictionary) -> void: if property.name in ["RandomMinPitchScale", "RandomMaxPitchScale"]: