Semi-Save childrens nodes

Godot Version

Godot 4.4

Question

Hi, I’m working on a plugin that needs to save nodes, and I already have a system for that, but I’m having a problem with the duplicate() method. My code saves the data in an array, but the children are temporarily saved. When the editor is reloaded, the child data is lost. I’ll add a part of the data saving function.

func SaveData() → void:
var auxListNode:Array
for node in NodeEditor.get_children():
if node is GraphNode or node is CinematicNode:
# duplicate the node
var dupNode=node.duplicate()
# appen to array
auxListNode.append([dupNode,node.name])
var auxConnections:Array = NodeEditor.get_connection_list() as Array
#save de data in Resource
CinematicResorse.SaveNodes(auxListNode,auxConnections,dicImportVar,dicImportTypeVar)

Then I have the option to redo the entire save so that it explicitly saves the children, but that already generated problems.

It’s not possible to save a Node to disk directly as is. You’ll need to use the PackedScene resource to save the node (and its children, check the documentation) to be able to save it to a file.

1 Like

Hello, after testing it a bit it worked completely, the only thing is that if someone needs to save the children you have to select them manually by script, the Owen here I leave a function that does it (use it before executing the pack() in the PackedScene)[quote=“mrcdk, post:2, topic:115490, full:true”]
It’s not possible to save a Node to disk directly as is. You’ll need to use the PackedScene resource to save the node (and its children, check the documentation) to be able to save it to a file.
[/quote]

func SaveNode():
var auxPack = PackedScene.new()
SetChildOwner(node, node)
var error = auxPack.pack(node)
allNodes.append(auxPack)

func SetChildOwner(node: Node, owner: Node):
for child in node.get_children():
if child is Node:
child.owner = owner
SetChildOwner(child, owner)[quote=“mrcdk, post:2, topic:115490, full:true”]
It’s not possible to save a Node to disk directly as is. You’ll need to use the PackedScene resource to save the node (and its children, check the documentation) to be able to save it to a file.
[/quote]

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.