Topic was automatically imported from the old Question2Answer platform.
Asked By
Squatnet
I’m trying to port a project over from 2.1 to 3.0.
I was in previous version using this code (autoload) to play my game music without any interruptions when switching scenes.
Follow tutorial how to use AutoLoad then just create AudioStreamPlayer and add to it music of youre choice. You can also create separate bus just for music if you need it.
extends Node
func _ready():
var music_file = "res://music.wav"
var stream = AudioStream.new()
var music_player = AudioStreamPlayer.new()
if File.new().file_exists(music_file):
var music = load(music_file)
music_player.stream = music
music_player.play()
# below are optional steps if you need more control
var music_bus_id = AudioServer.get_bus_count()
AudioServer.add_bus()
AudioServer.set_bus_name(music_bus_id,"music")
# connects music to master bus
AudioServer.set_bus_send(music_bus_id,"Master")
add_child(music_player)
music_player.bus = "music"