The right way of modifying a scene through plugin

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By BraindeadBZH


I have a plugin which act as a integrated map editor inside of Godot. The idea is that the plugin detect if the edited scene is of a certain type and then activate an interface where I can add new nodes through a custom UI. The new nodes are customs scenes. Both the map and the custom elements are declared as “tools”. Unfortunately it does not work as expected, most notably Godot when I add a node I can see them in the TreeView or in the Viewport but Godot does mark the scene as change and therefore I cannot save the change manually. If I save automatically through EditorInterface, the scene is not save exactly as is, nodes are misplaced and when I reload I don’t get the same scene.

So my question is simple, what is the correct way to modify a scene through a plugin and tools in order to be able to save it correctly afterward?


I’m not sure if that’s the trick, but you may commit your changes using the UndoRedo system. Maybe that’s why Godot doesn’t see your scene as modified?
Also if you create nodes you may set their owner as well so they show up in the tree and get saved.

Zylann | 2019-06-27 16:58

Yes you are correct, I should have updated the topic, because this is what I did. With UndoRedo I was able to correctly trigger Godot to take the change into account. Unfortunately I’m now facing another roadblock. Indeed, when you instantiate a scene through a tool, you cannot add children to it because there is no way, AFAIK, to flag the instance with “editable children”. Or to be more precise, you can add children but they won’t be saved.

BraindeadBZH | 2019-06-27 17:45

For that you should set the owner as the root of the edited scene.

Zylann | 2019-06-27 17:47

Setting the owner works for the currently edit scene but not if the scene you want to edit is a node of the edited scene. Normally to do that you have to check the option “Editable Children” otherwise the modification won’t be saved, and this option is not available through script.

BraindeadBZH | 2019-06-27 17:52

Better ask for a feature request then, I’m curious how that is done.

Zylann | 2019-06-27 17:56

Looks like a different issue, it’s a bout the feature being on by default rather than allowing tools to toggle it.

Zylann | 2019-06-27 18:07

I think it is close enough that if they implement this request, it then could be possible to also toggle the feature through script.

BraindeadBZH | 2019-06-27 18:10