Godot Version
Godot 4.7-stable
Question
I cant find a straight answer to a relative simple question: how can i save (in a file) node references that are contained in a var of type Node?
From what i understood (please tell me if i’m right) the problem is that the Node var mostly contains an ID that links to the node it refers to: this ID is created randomly at node instantiation, therefore even if i save it, loading a new scene will generete different IDs, making the saved ones useless.
Approach 1:
if it was possible to set custom IDs to node, then maybe the original IDs in the var would work even after loading a new game from file. Problem is, i cant find the method to set IDs, not sure if it even exist
Approach 2:
get rid of the IDs and node references, and work with node paths. Problem is that the code became more complicated: either every node reference became a get_node(path_node), or i double the var (one of type Node for the reference and one of type String for the path), but then i need to connect them after the tree scene is completely instatiated.
Approach 2.1:
It would be great if i could make a var of type string that contains the path of the node (this way it can be easily saved), and connecting it to the node using setter and getter (this way i can refer to the node directly). Something like:
var node_to_be_saved : String:
set(value):
node_to_be_saved=value.get_path()
get():
get_node(node_to_be_saved)
The problem here is that value is of type Node, while the editor is expecting a type String, so it doesnt work.
So, how do pro coders handle this problem?