Copy and saving nodes.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Hubber116sx
:warning: Old Version Published before Godot 3 was released.

Is it possible to get the current state of a dynamic node and add, or copy, it to another node?

For example, I have a node with a variable that changes to different values. I would want another instance of that node with the variable initially set to the same value as the original node.

:bust_in_silhouette: Reply From: avencherus

node.duplicate() seems not to be sufficient.

You can try something a bit more direct, like duplicate the node, and loop through the properties of the source node and copy them into the new node. In this example I have here, I choose only the ones that are user made in script.

var new_node = source_node.duplicate()

for property in source_node.get_property_list():

	# Script only properties/vars
	if(property.usage == PROPERTY_USAGE_SCRIPT_VARIABLE): 
		new_node[property.name] = source_node[property.name]