Godot Version
v4.2.1.stable.mono.official [b09f793f5]
Question
I am trying to make a custom audio manager as a plugin and need an object to create two new audio busses. One for the right ear and one for the left. Each with a low pass filter with a cutoff of 20000 hz.
Here is my script:
@tool
extends Node3D
@export var stream : AudioStream
@export_range(-80., 24) var volume_db := 0.
@export_range(0.01, 4.) var pitch_scale := 1.0
@export var playing := false
@export var autoplay := false
@export var stream_paused := false
@export_enum("Stereo", "Surround", "Center") var mix_target : int
@export_range(1, 100, 1, "or_greater") var max_polyphony : int
@onready var player = preload("res://addons/rtsa/spacial_audio_player.tscn")
var ind1 = -1
var ind2 = -1
var player1
var player2
func _enter_tree():
ind1 = AudioServer.bus_count
AudioServer.add_bus()
await get_tree().process_frame
ind2 = AudioServer.bus_count
AudioServer.add_bus()
await get_tree().process_frame
AudioServer.set_bus_name(ind1, name+":R")
AudioServer.set_bus_name(ind2, name+":L")
var pan1 = AudioEffectPanner.new()
pan1.pan = 1.0
var pan2 = AudioEffectPanner.new()
pan2.pan = -1.0
var cut1 = AudioEffectLowPassFilter.new()
cut1.cutoff_hz = 20000.0
var cut2 = AudioEffectLowPassFilter.new()
cut2.cutoff_hz = 20000.0
AudioServer.add_bus_effect(ind1, cut1)
AudioServer.add_bus_effect(ind2, cut2)
AudioServer.add_bus_effect(ind1, pan1)
AudioServer.add_bus_effect(ind2, pan2)
var player1 = player.instantiate()
player1.stream = stream
player1.volume_db = volume_db
player1.pitch_scale = pitch_scale
player1.mix_target = mix_target
player1.max_polyphony = max_polyphony
player1.bus = AudioServer.get_bus_name(ind1)
player1.name = name+":R"
var player2 = player.instantiate()
player2.stream = stream
player2.volume_db = volume_db
player2.pitch_scale = pitch_scale
player2.mix_target = mix_target
player2.max_polyphony = max_polyphony
player2.bus = AudioServer.get_bus_name(ind2)
player2.name = name+":L"
func _ready():
if not Engine.is_editor_hint():
add_child(player1)
add_child(player2)
func _exit_tree():
AudioServer.remove_bus(ind2)
AudioServer.remove_bus(ind1)
for child in range(get_child_count()):
remove_child(get_child(child))
However, instead this is what I get:
Two blank busses
Upon restarting, however, if I leave the blank busses there I get two more correctly formated audio busses:
This continues with each restart adding two more correct busses.
I just want the two though with the correct effects on them. I have tried a lot but I feel like I am doing something either wrong, or not supported fully. If anyone can help that would be greatly appreciated. Let me know if you need any other info. Thanks in advance :3