Scale resets when changing custom minimum size

Godot Version

4.6.2

Question

When I change the custom minimum size of a MarginContainer, its HBoxContainer child node will reset its scale.

margin_container.custom_minimum_size = newSize
h_box_container.scale = scale                      # The scale is always 1.0

If I use:

margin_container.custom_minimum_size = newSize

await get_tree().process_frame                     # The scale is 1.0

h_box_container.scale = scale                      # The scale is correct

Then, I understand that the scale is correctly set once we have drawn.

The problem is that this solution creates a frame when the scale is reset to 1 while waiting to draw for the scale.

How can I get rid of this frame that always has a scale of 1.0?

Should I create a shader and try to discard this frame?

Containers will reset their children rotation and scale when their transform change. You can use a Control as an intermediate between the container and content but you will need to sync its size between the content and the Control.

If you can update to Godot 4.7 you will be able to use the new offset transform feature:

Make MarginContainer a child node of AspectRatioContainer. So this will preserve it’s aspect ratio.

So your scene tree should look like this

HBoxContainer
|- AspectRatioContainer
   |- MarginContainer

I saw something about it and thought that was not for my case. I will look into it, thank you very much! This version of Godot really fits my project too; that is why I have not done it yet.

I will look into it, thank you very much!

I have not been able to solve it with AspectRatioContainer node; it resets after changing the custom minimum size of its parent. I have been able to solve it with offset transform, Godot’s 4.7 new feature. I will have to move to Godot’s newer version. Thank you very much for your help!