#Editor plugin UI scene files get modified after the UI scene in instantiated and modified by code

1 messages · Page 1 of 1 (latest)

faint lake
#

I'm making a custom plugin with its own UI for the bottom panel.

The plugin UI scene has its subscenes all over the node hierarchy.

The plugin should change its contents (labels, colors, styles, textures — everything), but here's the problem.

Every time the plugin is enabled, and the subscenes' _ready() methods are called, the original scene files ends up also modified in the 2D viewport, which make it very hard to edit plugin UI scene files and test the changes after reloading the plugin.

No errors, just those scene modified in the 2D viewport.

Here's one of the cases I can describe:

  1. I keep my plugin UI scene opened in the 2D viewport and then enable my plugin.
  2. The plugin UI appears, already with texts, colors, and icons, modified (for example, every time I want to change the UI scene and scene what happens when I reload).
  3. I press Reload Saves Scene and confirm the action.
  4. The 2D viewport now shows me the plugin UI scene with all the changes made in step 2, like if it was alwyas there.

What I've already tried:

  • Checking all the node tree in the 2D viewport and the editor interface and check if the instantiated scene belongs to that viewport tree. I tried parents, children, and owners.
  • Engine.is_editor_hint()/is_embedded_in_editor() (neither one sees the difference between scenes in 2d viewport and scenes added into EditorInterface as plugin UI)
  • loading insteand of preloading the scene

Googling the problem gave me nothing but forum topics about plugin changing what's already there in the viewport. Sadly, that's not what my problem is about.

So I've got a question: how could the editor separate the plugin's UI scene file from its instance added in the editor UI?

Technical Information:

  • Godot v4.4.1.stable.flathub [49a5bc7b6]
  • GDScript only
  • Linux Mint 22
faint lake
#

UPD: I guess I've finally made it work the way I need.
The key to the solution was using metadata (that might work with scene script variables as well, but I didn't test that).

This is how it works.
The plugin's "root" UI scene can have a specal metadata flag. And only the plugin script sets it to true, marking the UI as added by that plugin and nothing else.

And if you open the same scene in the viewport so you could make changes to the UI, that metadata flag won't be there.

Then every time I need to update an element in the plugin's UI, I just check all the parents up to the very root, and only if any "predecessor" has the metadata set to true, the node is allowed to change. That allows me to prevent metadata propagation all the way down the UI tree.

If you have any better solutions for that, fell free to post it here, that would be highly appreciated. 🙂