![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | The_Black_Chess_King |
To do this:
onready var WorldNode = Node
_ready():
If get_parent().exists(): #How to do dis?
WorldNode = get_parent().get_node("WORLD")
#This path will be a standard for all my maps.
Because I would be able to test scenes separated, without having to load the main maps. Using export path vars does work, but it requires you to manually load in the inspector, also tried get_owner
but didn’t achieved much in that sense of finding if a parent exist.
The map structure: Imgur: The magic of the Internet
I would be able to test scenes separated
What do you mean by this? Have you made a series of levels that lead on from each other?
The question doesn’t really make sense because to use get_parent()
you need a child, if the parent doesn’t exist the child won’t exist either.
Magso | 2019-12-09 14:09
Oh I see what you mean, the real name of the question should have been, how a node check if he has a parent?
Well, I have a UI Node which is saved as a separate scene, it needs to know what node is the WORLD
, to drop items you selected in the inventory.
This works if I load my main map and use direct path to this node, my map scene is structured like so :
Imgur: The magic of the Internet
The node in question is UI_Master
and the node which I drop items is WORLD/ITEM
The_Black_Chess_King | 2019-12-09 14:14
Hmm, I think by design my logic is wrong, what I need is to pass a signal to the World
, and he will create the items, will work much better and the UI_Master
doesn’t need to know who World
is.
Still, is it possible to check if a node has a parent?
The_Black_Chess_King | 2019-12-09 14:40
The nodes will always have a parent, Godot basically works like this, get_tree().get_root().Top node in the scene aka get_owner()
. You just need to reference the correct node to then add the items to it.
Magso | 2019-12-09 15:54