system
November 24, 2016, 6:08pm
1
Attention
Topic was automatically imported from the old Question2Answer platform.
Asked By
Sprowk
Old Version
Published before Godot 3 was released.
I have multiple scenes and all of them have buttons. What Im trying to do is have 1 global SamplePlayer and when any button is pressed mysample is played.
get_parent().get_node(SamplePlayer).play("mysample")
Tried code above but for this I need SamplePlayer in every scene…
When im trying to create global sample.gd I dont know how to setup sample library.
system
November 24, 2016, 7:48pm
4
Reply From:
eons
To keep it visual, a scene (tscn/scn) with a sampleplayer can be added as autoload, then:
get_tree().get_root().get_node("SamplePlayerName").play("mysample")
#if the sampleplayer is root on autoloaded scene (check remote inspector tree)
A has_node
check first may be good.
Or better, add it to a group too, then on the buttons:
get_tree().call_group(0, "global_sample_group", "play","mysample")
This will work even if the global is not loaded (like for tests) so you wont have to check has_node
all the time.
There are many other ways to work with groups.
So I have to create new scene just with sampleplayer - make it autoload and then i can call it from any scene right?
Sprowk | 2016-11-24 20:02
Exactly, is useful for cases where you have a common scene for the whole game (like music, backgrounds…).