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.

in Engine by (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]
by (5,203 points)
edited by
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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.