How do I Make Local a node, programmatically via script?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By wyattb

How do I Make Local MyLineEdit node, programmatically via script?
I need this so if I make a change to the original MyLineEdit scene, it does not affect the one I added in the Control Scene. I tried changing the owner of the instance, but does not seem to work.

This is what the engine C++ does:

	undo_redo->create_action(TTR("Make Local"));
	undo_redo->add_do_method(node, "set_filename", "");
	undo_redo->add_undo_method(node, "set_filename", node->get_filename());
	_node_replace_owner(node, node, root);
	undo_redo->add_do_method(scene_tree, "update_tree");
	undo_redo->add_undo_method(scene_tree, "update_tree");
	undo_redo->commit_action();

So I assume a GDScript equivalent would be (without undo/redo):

node.set_filename("")
node.set_owner(scene_root)

I guess this turns the instance into a non-instance.

Zylann | 2019-12-02 18:49

Yep that did it. Thanks for looking it up. Would be nice if that were a single method.

I guess setting the filename to empty string, severs the relationship from the original scene. Interesting.

node.filename=''
node.owner=get_tree().get_edited_scene_root()

wyattb | 2019-12-03 01:09

:bust_in_silhouette: Reply From: wyattb

see comment above.