Godot Version
4.2.1
Question
I created an autoload scene to handle the music for my game. In it, there’s a function for fading in and out music by tweening the volume of the AudioStreamPlayers. For some reason, when using this function, this completely breaks all sound in the game until the tween is done. The other two functions work completely fine.
I know it’s not an issue with how I used the tween, since I tested the function outside of an autoloaded scene and it worked fine. Unfortunately, I need it in the autoloaded scene to work with the rest of my game’s logic.
So far, I haven’t found anyone who’s run into a similar issue. Any help would be greatly appreciated. Thank you.
extends Node
@onready var game_music = $GameMusic
@onready var sunrise_music = $SunriseMusic
@onready var menu_music = $MenuMusic
@onready var shoot_the_saucers_music = $EasterEggMusic
func play_music(music:AudioStreamPlayer, play:bool=true, volume:float=1)->void:
if play:
music.play()
music.volume_db = linear_to_db(volume)
else:
music.stop()
func set_volume(music:AudioStreamPlayer, volume:float):
music.volume_db = linear_to_db(volume)
func smooth_fade(music:AudioStreamPlayer, final_vol:float, time:float):
var tween = create_tween()
tween.tween_property(music, "volume_db", linear_to_db(final_vol), time)