Topic was automatically imported from the old Question2Answer platform.
Asked By
Macryc
Is it possible to esport a node path to a singleton script so that it can be accessed by other nodes even if it changes its position in the tree?
Let’s say I have a node which is is being accessed by other nodes via get_node. In get_node I’m prviding full paths from root. But, if that node needs to move for any reason (eg, I want to reparent it) the path will change and I will have to update the path in all scripts currently accessing the node. I’m looking for a way to make godot find the node wherever it happens to be in the tree. I was thinking, if I could somehow export its path to a global singleton and access it from there?
Storing the path in a singleton will still loose reference once the node is moved unless it is updated. An easier way to do this is to store the node itself in the singleton and use get_path() if necessary. It is also possible to use find_node() like this
get_node("/root/scene node").find_node("name of node")
wow, didnt know you could find nodes that easily in a hierarchy. I need to try this. Thanks!