Reposition children of instanced scene

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

I have a scene which draws some stuff to the canvas, and under certain conditions “pops up” an instanced scene on one part of the canvas. So something like:

Root Node
|-> sprites etc.
|-> Instanced Scene "pane"
      |-> labels, buttons, etc.

When I instance the pane, it appears at the full dimensions and positions of the original, while I would like it to only cover e.g. the left third of the screen, and all the children of the pane to reposition accordingly. I can do this manually by fussing with positions in pane._ready, but that’s not scalable as the pane grows in detail (gets more children).

I don’t want to make the instanced pane a static child of the root because I might have multiple different panes shown at different times, and editing them all in one scene would be very difficult.

How can I get the instanced scene to resize/reposition its children when I instance it?

:bust_in_silhouette: Reply From: rossunger

If the instanced scene is a Control node, then you can use rect_size and rect_min_size properties, and margins and such. If your node heirerarchy is structured right all the children will adjust the right way when you realize the top node.

You can also the use the scale property, but they comes with other challenges, unless you’re just uniformly resizing

If it’s not a Control node, but a node2d type node, then you have to use scale I think

The way to structure it is using anchors and margins… This tutorial might help ya:
Control Node | Godot Basics Tutorial | Ep 41 | Godot Tutorials

rossunger | 2022-02-11 17:34