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.

This no longer works in Godot 4.3-beta3.

It’s a very recent breaking change. I’ve been relying on this “hack” for my addon for quite some time now, and it’s been stable for all Godot 4 versions up until now.

In my use case I am programmatically doing “Make Local” after dragging a GLTF file into my scene. After doing node.scene_file_path = "", it does not seem to be possible to make changes to that scene any more.

If anyone else has a use case or can provide a scenario they would want to programmatically “Make Local” that might help me find the source of the issue.

Edit: I don’t think the “Make Local” programmatically is broken. Something else changed with the pipeline. I found a hack/workaround in my case.