Audio bus configuration script

Sample Object.zip (5.8 KB)
Volume Adjustment Required Script.zip (5.0 KB)
Volume Adjustment Sample Project.zip (222.6 KB)

AudioBusControlButton User Manual

AudioBusControlButton is a Button that, when pressed, calls the AutoLoad AudioBusSettings and performs volume level switching, volume increase/decrease, and mute toggling on the specified AudioServer bus.
The settings are saved by AudioBusSettings to user://audio_settings.cfg and restored on the next launch.

Setup

  1. Create a scene for AudioBusSettings

    1. Create a new scene
    2. Set the root node to Node
    3. Attach AudioBusSettings.gd to the root node
    4. Save it as an example at res://autoload/AudioBusSettings.tscn
  2. Register the created scene in AutoLoad

    1. Open Project Settings
    2. Open AutoLoad
    3. Specify res://autoload/AudioBusSettings.tscn in Path
    4. Set the AutoLoad name in Name
      Example: AudioBus
    5. Press Add to register
  3. Configure the export settings of AudioBusSettings in the scene

    1. Open AudioBusSettings.tscn
    2. Set the values in the Inspector of the root node
      config_path: Example user://audio_settings.cfg (no change needed)
      config_section: Example audio
      include_master: Whether to include the Master bus
      exposed_buses: If empty, all buses are included; otherwise, only the specified names are included
      volume_levels: Linear candidates for level switching from 0.0 to 1.0
      min_db: Lower limit to convert linear 0 vicinity to dB
  4. Place AudioBusControlButton

    1. Add a Button node to the scene
    2. Attach AudioBusControlButton.gd to the Button
    3. Configure in the Inspector
      autoload_name: Must match the AutoLoad name, e.g., AudioBus
      refresh_bus_list: Turn ON once to update the list, then turn OFF again
      target_bus_name: Select the target bus from the dropdown (if the dropdown doesn’t update, save the project and reopen it)
      mode: Select the action when pressed

Minimal Configuration

Minimum configuration for use as level switching.

  1. Set mode to CYCLE_LEVELS
  2. Leave cycle_levels_percent empty
    If empty, AudioBusSettings.volume_levels will be used
  3. Run and press the button
    Volume switches to the next candidate, and after the last, it returns to the first
  4. Stop and restart
    If saving is enabled, the previous settings will be restored

Key Settings

mode

  • CYCLE_LEVELS: Finds the candidate closest to the current value and switches to the next one
  • MUTE_TOGGLE: Toggles mute
  • VOLUME_UP: Increases linear volume by step_percent_points
  • VOLUME_DOWN: Decreases linear volume by step_percent_points

cycle_levels_percent

  • Specifies candidates in percent for CYCLE_LEVELS
  • Example: 0, 25, 50, 75, 100
  • If empty, AudioBusSettings.volume_levels is used

step_percent_points

  • The increment/decrement amount for VOLUME_UP and VOLUME_DOWN

Display

  • If auto_label is true, text is automatically updated; set to false if you want to fix it
  • label_prefix is the prefix string; if empty, the bus name will be at the beginning
3 Likes