Programmatically changed scene instance wont save

Godot Version

Godot 4.2

Question

I’m creating an editor plugin that instances multiple times the same scene but with different configurations inside another scene. All of that programmatically.
The configurations may vary, but it is always just hiding nodes inside the instanced scenes.
When I create instances of my PackedScene, save the main scene and load it back up, I still see my instanced scenes but all the changes I made are gone and all the instanced scenes are back to their default states.

So, is it possible and how am I supposed to save all changes made to the programmatically instanced scenes ?

When ever you create any kind of node, you will typicall add it as a child to another node in the scene. Easy right?

The trick that the documentation here doesn’t explain well, if you want that to be saved to the Packed Scene.

You need to set the owner property of the newly created node to the Root Node of the Scene - which is not necessarily the node’s direct parent.

I like to think of it as: you are telling Godot which Packed Scene owns that Node’s data.

An EditorScript I use has something like this in it:

var root_node = get_scene()
root_node.add_child(rigid_body)
rigid_body.owner = root_node
mesh.reparent(rigid_body)
mesh.owner = root_node
1 Like

Hi Oddity, thank you for your answer !

I just read it, and that would have helped but I just went on another way of doing this.

Again, thank you !

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.