Changing Global music volume

Godot Version

V4.7

Question

Hi, I’m having some trouble adjusting the volume for my music. I’m able to adjust the sound, but I can’t figure out music. I also made music Global so that it doesn’t change between certain secenes.

Below is the node layout.

BTW, the HSlider is separate

image

extends HSlider

@export var bus_name : String
# bus_name for the HSlider is either Music or Sound
# Yes, the audio bus has the same names (Master, Music, Sound)

var bus_index : int

func _ready() → void:
	bus_index = AudioServer.get_bus_index(bus_name)
	
	value = db_to_linear(AudioServer.get_bus_volume_db(bus_index))
	
func _on_value_changed(value: float) → void:
	AudioServer.set_bus_volume_db(bus_index, linear_to_db(value))

This is the Global. Called MusicControl.

extends AudioStreamPlayer

var current_music = preload(“res://Assets/SoundsAndMusic/Lost In The Desert.wav”)

func _play_level_music(music : AudioStream) → void:
	# Don't want the music to change between certain scenes
	if stream == music:
		return

	stream = music
	play()

func play_general_music() → void:
	_play_level_music(current_music)

Code to call MusicConytol: MusicControl.play_general_music()

Is your music AudioStreamPlayer set to the Music bus? What does “can’t figure out music” mean? What happens, and what did you expect to happen?

There is a music control node:

imageThis has the AudioStreamPlayer code as seen above

imageThis is the bus

What does “can’t figure out music” mean?

I want to change the volume of the music using a slider.

What happens, and what did you expect to happen?

Nothing happens when I try to change the slider for the volume. I’m hoping to have the volume change via the slider, so that’s what I’m expecting.

As I said before, changing the slider for the sound does change the volume of sound

How did you create that global? Did you autoload the script .gd or your MusicControl scene .tscn?

I autoload the script

image

Thank you! When autoloading the script will not include any of your scene information, instead creating a default AudioStreamPlayer which targets the Master bus. You can change this global to use the Scene instead

Ah, that’s it working. Thank you.