0 votes

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.

asked Jul 24, 2017 in Engine by Hubber116sx (36 points)

1 Answer

+1 vote

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]
answered Jul 24, 2017 by avencherus (4,815 points)
edited Jul 24, 2017 by avencherus
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.