Is there a way to modify scenes programatically?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mofro
:warning: Old Version Published before Godot 3 was released.

For example, I incorrectly named a bunch of nodes, is there a way to rename them all with a script?

A repl for the editor would be really cool actually …

:bust_in_silhouette: Reply From: Hinsbart

Sure, just load your scene and do your changes on an instance of it. Then you can save it back to the disk resource using ResourceSaver.save().

Short example:

var scene_path = "res://my_scene.tscn"
var scene = load(scene_path)
var root = scene.instance()
for node in root.get_children():
    node.set_name(new_name)
scene.pack(root)
ResourceSaver.save(scene_path, scene)

Even though the OP didn’t say thanks I’d like to. That’s great help for something I’m facing at present.

Robster | 2016-12-22 03:19