Godot: Anchor and margin are been reset for VBoxContainer/Panel inside ScrollContainer

Created on 1 Aug 2017  路  5Comments  路  Source: godotengine/godot

Operating system or device - Godot version:

ALL - 3.0 ALPHA1

Issue description:

Inside an ScrollContainer, The VBoxContainer and it Panel child anchor and margin are reset to all begin and 0. It always happens when the following actions are performed:

  • Scene is loaded (in the editor or in the game)
  • Nodes are added or removed to any descendant of the VBoxContainer or itself

Additionally, sometimes (not reproducible in the attachment project), while resizing the VBoxContainer or its Panel child will suffer this issue after increasing the width to some specific amount. However this cannot have be reproduced in a minimal project yet, please take it in consideration.

Please note that this also applies to HBoxContainer with other parent nodes, but is been omitted for brevity.

Steps to reproduce:

  1. Open Godot 3.0 ALPHA1 editor on any desktop platform
  2. Create a new project
  3. Create a Control root node
  4. Create a TabContainer node under the root Control node
  5. Create a Tab node under the TabContainer node
  6. Create a ScrollContainer node under the Tab node
  7. Create a VBoxContainer node under the ScrollContainer node
  8. Create a Panel node under the VBoxContainer node
  9. Optionally add some nodes to the Panel node, like Label, LineEdit or Button for easier preview
  10. Set Panel min size as 0, 50
  11. Except Panel and it descendant, set anchor and margin as it follows (ordered as left, top, right, bottom):

    • Anchor: begin, begin, end, end

    • Margin: 0, 0, 0, 0

  12. Set Panel anchor and margin as it follows (ordered as left, top, right, bottom):

    • Anchor: begin, begin, end, begin

    • Margin: 0, 0, 0, 50

  13. Run the scene
  14. Observe the issue in the running game window
  15. Close the scene
  16. Duplicate Panel
  17. Observe the issue in the editor

Expected results.

The anchor and margin for VBoxContainer and Panel are kept.

Current results.

The anchor and margin for VBoxContainer and Panel are reset to all begin and 0, except for the Panel height that is kept as the min size Y.

Workaround.

For simple GUIs the following script can be used, but may not work properly on more complex GUIs:

func _process(delta):
    set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0)
    set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0)

Link to minimal example project:

The following attachment has a simple project with an example of this issue. The example contains a sample of the bug and and example of the workaround.

bugs.zip

See also.

8726

archived

Most helpful comment

@reduz does this means that it is not possible to have responsive containers without having to set the size in every loop through an script?
I am using Godot to do complex GUIs, and to be honest it is really impressive how simple is to make multi-tabbed responsive complex GUIs with minimal scripting for the layout. However this limitation is pretty annoying, and if it is by design it is hard to understand the objective of such behavior. Is really not possible to change this behavior?

All 5 comments

Can confirm margins are being reset when the game starts / scene is reloaded. This happens for MarginContainer and all other *Container nodes as far as I can see...

This is not a bug, containers override any setting you change in margins. It's by design.

Yes, I had a closer look now - you need to set this under "Custom Constants" -> Margin properties.

@reduz does this means that it is not possible to have responsive containers without having to set the size in every loop through an script?
I am using Godot to do complex GUIs, and to be honest it is really impressive how simple is to make multi-tabbed responsive complex GUIs with minimal scripting for the layout. However this limitation is pretty annoying, and if it is by design it is hard to understand the objective of such behavior. Is really not possible to change this behavior?

I don't see any Margin properties under Custom Constants.

Was this page helpful?
0 / 5 - 0 ratings