#Audio Bus for @exported variable

6 messages · Page 1 of 1 (latest)

kind drift
#

Hi!

I have an exported variable with a music file. How can I add this variable to an Audio Bus?

@export var music_sample: AudioStream
bright kraken
#

You should use AudioStreamPlayer, AudioStreamPlayer2D or AudioStreamPlayer3D nodes (depending on use-case).

#

If it's music and you don't want the direction of the sound to change, use AudioStreamPlayer.

kind drift
#

Hi Fluffeu, thanks for the reply. I jerry-rigged it by doing this instead...

I added a new AudioStreamPlayer and called it MusicSample and then created a new @onready variable...

@onready var music_sample = $MusicSample

This works, as I was able to add this to the desired bus. Is there no way to do this in codee using my initial setup?

bright kraken
#

Well, you can creade a new AudioStreamPlayer node from script and add it as your child, set the music sample, than play it

#
add_child(stream_player)
stream_player.stream = music_sample
stream_player.play()```