|Topic was automatically imported from the old Question2Answer platform.
I have 2 AudioStreamPlayer2D, one of which is in the main scene. I tryed to access both from a different scene using:
onready var game_music = get_node("/root/path_to_music")
The one in main scene caused me no problem, but the other one returned null!!!
Attempt to call function ‘is_playing’ in base ‘null instance’ on a
How can I access AudioStreamPlayer2D in other scenes!? and does been a main scene or not have any thing to do with this problem?
Thank you in advance
Here’s the thing: “scenes” don’t matter when the game is running. All you have is a bunch of nodes in the scene tree.
The error you’re getting is because the path you have in that
get_node() is returning
null instance because it’s invalid. You need to look at your scene tree and use the correct path to the node you want.
If you post a pic of your scene tree, I can probably show you exactly.
Thank you for your answer…
I understand that this error could be generated from a wrong path, but i highly doubt it …i have checked a million time!!
onready var game_music = get_node("/root/main/backgroundMusic")
again your help is much appreciated.
What node is the script with that line on?
onready is probably your problem. Children become ready first, so “main” is going to be ready last. Calling this in the ready of a node that’s further down the tree will not work.
kidscancode | 2020-05-02 00:36
on ready line is in a different scene in the same directory as all other scenes
i used the same line to access
main_menu scene and it worked but
backgroundMusic loaded from
main scene is causing problems
The “directory” has nothing to do with it. When you run the game, the nodes are all in the scene tree, and they become ready in reverse tree order. You can’t call a node that’s above during
kidscancode | 2020-05-02 01:05