#Audio stays across scenes
10 messages · Page 1 of 1 (latest)
I'm usually using a global node for audio - so some kind of AudioManager with playback methods, that can be used from everywhere. global nodes can be registered in the project settings and exists in the scene tree parallel to the active scene
How can I create a global node? Just create a new scene and set that scene to autoload or how?
yep exactly
if you add an class_name then you'll have autocomplete as well
but the class_name must be a different name from the name you load it in autoload - so for example make the class_name AudioManager, load the scene as Audio and then you can use everywhere Audio.play_bgm("main") for instance
Nice, I managed to do it! Thanks for the help. Also, I didn't quite understand what you were trying to say with the classes and how that could do the trick too
basically, if you make your Audio scene with a attached script like
extends Node2D
class_name AudioManager
func play_bgm(bgm_name: String) -> void:
# some logic to start the audioplayer of the scene
and then autoload it as Audio, you may start typing in some other script file Audio. and then you get play_bgm as a method suggestion
then you don't have to look it up how your function was called as the gdscript interpretor already knows what functions are available for your use
Oh I see, but why does adding the class_name make the difference whether play_bgm is suggested or not? My other autoload script doesn't have its own class_name but still has all its variables and methods suggested.