How to make a reusable Window component

So, I have made several menu scenes which all essentially replicate this same structure.

image

I would like to make a higher level share component to standardise this.

I’ve made loads of reusable “components” using scenes, but they have always been standalone, never “wrappers”. (eg a “player”). I’ve never needed to nest anything under a re-usage scene…

If I make these a scene, how do I tell Godot that any children added under it when it’s used in another scene should be added under the MarginContainer?

Or am I approaching this incorrectly?

I’m not entirely sure what your question is. Are you trying to figure out how children for a BaseWindow instance can be placed inside the MarginContainer? If so, the only editor-option is to right-click the scene instance and enable Editable children. This will show the children within the instance and allow you to place nodes anywhere e.g. MarginContainer.

However, I’m not sure what would happen if you then changed the source scene after adding nodes to multiple instances of it – you will have to test that.

As for whether this is the correct approach to your problem, that is hard to answer as I don’t know the surrounding context that your windows are present in.


Hopefully this helps. If not, don’t refrain from asking more questions.

Hi - Thanks @Sweatix - sorry the question wasn’t clear.

So my goal is for the screenshot to be the “base” or “common” wrapper around all my windows.

So… I guess I need to make it a component rather than a scene?!

What I’d like - and its possible that this is impossible :wink: - is that I’d convert the screenshotted scene into something reusable (like a scene) and then all my other windows would either be a Control node with that as a child and then the contents of the window as a child of that imported scene node… OR, if it was a “component”, the actual node type of each window would be BaseWindow.

That way every window will have the same styling, close button, etc.

At the moment, I have about 4-5 windows (with more needing adding) and I’ve already spotted inconsistencies creeping in (window title colour, different ninepatch texture, missing close button, etc); it will only get worse :wink:

Any thoughts?

Ahh - this might be a case for Inherited Scenes…

image

So now I can add my child elements under the node I need to, but all the shared/inherited ones are marked in yellow:
image

I just checked; when I changed the “parent” BaseWindow, it applied to the “child” window automatically. Perfect!

Yeah, inherited scenes seem like a good fit for this.

Good luck!

1 Like

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