0 votes

I'm building an editor tool, and i'm trying do the following:
- take a Node and it children from the sceneTree
- pack them into a PackedScene and save to file,
- add them back to the main scene, maintaining the reference to the file

This is the same functionality as SaveBranchFromScene... is it possible to do this from code?

I can instance a scene and add it back into the tree, but it's not a linked instance... like when you right click on a node and press "Make Local".
I need it to be a linked instance, so that when I edit it the file elsewhere in the future, it'll update here too.

Godot version 3.4.2
in Engine by (1,258 points)

1 Answer

+1 vote

Wow. the answer is so simple. I can't believe how long I spent looking for this :P
You just set the instanced node's "filename" property.

var oldScene = get_node("oldScene")
var packedScene = PackedScene.pack(oldScene)
ResourceSaver.save("res://scenefile.tscn", packedScene)
oldScene.filename = "res://scenefile.tscn"
by (1,258 points)
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.