Hello,
After a bit of research, i found a way that works to edit/duplicate scene in a tool script.
The script assumes that you already have a "template" .tscn somewhere in your tree.
load the template
var template_path = "res://path/to/your/scene.tscn"
var template = load( template_path )
create a temporary instance of your template
var tmpl_instance = template.instance()
modify your template
tmpl_instance.get_node( "cube" ).scale = Vector3(2,0.5,2)
tmpl_instance.get_node( "collider" ).scale = Vector3(2,0.5,2)
create a new PackedScene containing your modified instance
var ps = PackedScene.new()
var result = ps.pack(tmpl_instance)
if result == OK:
ResourceSaver.save( template_path, ps )
your template is overwritten, if you open the scene in the editor, you will see that changes have been applied
template = load( template_path )
you can reload the template directly after the operation and start using it
If you adapt the path, you can create copies of your template without overwriting it. Might be useful to produce variations of a basic scene.
This is an adaptation of the example provided in PackedScene documentation :)
Made on v3.1.1 stable official