How to interpolate Tween on Audio Bus?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Krasapan

I tried to do it in different ways but nothing comes out. My code looks like this (I know that interpolate_property method doesn’t indicate what is needed at all, I showed it for clarity):

func _on_StartButton_pressed():
	fade.fade_in()

	var tween = Tween.new()
	add_child(tween)
	tween.interpolate_property(AudioStream, "volume_db", 0, -80, 1, Tween.TRANS_QUART, Tween.EASE_IN, 0)
	tween.start()

	yield(get_tree().create_timer(transition_duration), "timeout")
	get_tree().change_scene("res://Main.tscn")

I want to interpolate audiobus I need (in my case it’s Music, index 1), not master audio.
Is it possible? If so, how?

:bust_in_silhouette: Reply From: kurtsev0103
  1. You must create a method that will change the volume of your bus.
  2. Use interpolate_method in your tween.
tween.interpolate_method(self, "change_audio_bus_volume", 0.0, -80.0, 1.0)
tween.start()
func change_audio_bus_volume(value: float):
	var index = AudioServer.get_bus_index("bus_name")
	AudioServer.set_bus_volume_db(index, value)

Note that this will most likely cause audible cracking as per https://github.com/godotengine/godot/issues/32882. As a workaround, modify the volume of individual AudioStreamPlayer nodes instead.

Calinou | 2021-11-16 16:05