![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | FellowCoder |
So the console is giving me this error and i have no idea whats causing it, i only saw one guy having the same issue on reddit but nobody helped him, here is the part where i try to put a texture a texture in a sprite that is on another scene(its not the main scene, its my character scene):
get_node("/root/Spaceship/Sprite").texture = load("res://images/Heavy.png")
its not the main scene, its my character scene
Is the path correct? The scene node is called “Spaceship” and the player scene is called “Sprite”?
Magso | 2020-03-27 02:15
Open if the pictures are bugged:
Arthur Melo has shared 1 photo with you! | Flickr
Arthur Melo | Flickr
FellowCoder | 2020-03-27 02:49
Your scene node is “Main” so from the root the path needs to be get_node("/root/Main/Spaceship/Sprite")
Another way would be to use get_owner().get_node("Spaceship/Sprite")
Magso | 2020-03-27 02:56
It does not work either
FellowCoder | 2020-03-27 03:06
You could also use find_node
and store it as a variable.
onready var spaceship = get_node("/root").find_node("Spaceship")
#and use
spaceship.get_node("Sprite")
Magso | 2020-03-27 08:49
Anc once you located the node with find_node
, you can use get_path()
and print the result to see what the correct path would have been and spot your mistake:
func _ready():
print(get_node("/root").find_node("Spaceship").get_path())
njamster | 2020-03-27 11:33
Now it gives me the error:
“Attempt to call function ‘get_node’ in base ‘null instance’ on a null instance”
FellowCoder | 2020-03-27 13:41
the scene changes to the character selection scene ,that is where my script is located, that after goes to the one called “Main”
Is the Spaceship scene in the character selection or loaded in Main? If it’s loaded in the Main scene it won’t exist in the character selection where you’re saying the script is.
Magso | 2020-03-27 20:09
In the character selection…How can i have access to it?
FellowCoder | 2020-03-27 20:15
In that case get_node("Spaceship/Sprite")
should work.
Magso | 2020-03-27 20:35
What about if it were on another scene, how could i do it?
FellowCoder | 2020-03-27 23:13
By having the Spaceship assign itself to a singleton variable, then it can be accessed from any script.
Magso | 2020-03-27 23:25
How can i do that?
FellowCoder | 2020-03-27 23:34
Have a look at them.
Singletons (AutoLoad) — Godot Engine (3.2) documentation in English
Magso | 2020-03-27 23:42
Is it the only way to do that?
FellowCoder | 2020-03-28 00:55
The alternative is to instance and queue_free
the scenes without changing the scene root whilst Spaceship exists.
Magso | 2020-03-28 01:13
Thank you so much man, you really helped me. Btw, how do i chose your answer as best answer and close this post??
FellowCoder | 2020-03-28 01:18
No one’s posted an answer, these are all comments. There’s not really a correct answer to give other than suggesting all the possible ways of referencing a node.
Magso | 2020-03-28 02:18