Tweening music isnt working

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

i have

func fade_out(stream_player):
	tween_out.interpolate_property(stream_player, "volume_db", 0, -80, transition_duration, Tween.TRANS_LINEAR, Tween.EASE_IN, 0)
	tween_out.start()

func _on_Tween_tween_completed(object, key):
	object.stop()
	object.volume_db = 0 # reset volume

im setting it in _process with fade_out(dayTheme) and have these too onready var tween_out = get_node("Tween"), onready var dayTheme = $DayTheme
but when the music should fade out, it doesnt, the duration is 2 seconds and in those 2 seconds the volume doesnt change, and after the 2 seconds it just cuts out.

:bust_in_silhouette: Reply From: Adam_S

If you place your fade_out() function within _process(), it gets called every frame.
I think this would set volume_db to 0 for every frame and when the first tweening is completed your audio stops.

To prevent that you could do something like this:

func _process(delta):
    if not tween_out.is_active():
        fade_out(dayTheme)

But I guess there are better places to call your fade_out() function.

Note that a tween duration of two seconds may sound still pretty abruptly.
I would suggest you to increase the time or playing around with the other easing and transition types.

This image could be helpful.