0 votes

I have an hboxcontainer with 3 control node children. They are each set to fill and expand. While in the editor, if I change the visibility of one to off, the other two will expand to fill in the space. Likewise when I turn it back on, the other two shrink. However, when I change to visibility in code during runtime, they don't update their rect_size.

HBoxContainer

  • Slot1
    Slot2
    Slot3

The children start with visibility off, except the first child. I've tried turning that off too.
I am changing visibility using .visible = true.
I'm avoiding hard coding rect_size so that they will easily adjust with screen size.

I've tried using NOTIFICATION, though I might be using it wrong. I've tried sort_queue on the hboxcontainer after making them visible. I've tried to call draw() and update() to them as well, though I could have done that wrong too.

I'm hoping this is just an obvious oversight on my part and not a limitation of the engine.

in Engine by (35 points)

1 Answer

+1 vote
Best answer

Yeah, after digging around in canvas_item.cpp and other bits of engine code, I found that visibility handling is quite subtle (as of 3.2.3). The intention is to optimize performance by not calculating for nodes that aren't showing in the tree, but unfortunately this means that any *other* nodes or script logic that make use of hidden node data (rect, etc.) will be using dirty/incorrect values.

I haven't found a clean way to solve this yet, and the best advice I can give so far is to make sure things are visible for long enough to have their values updated. You can start visible and CallDeferred("hide") (C#). This gives just enough time to lay things out. Or you could start hidden, Show(), and then wait a frame before making use of data updated on visible nodes. You may have to manually Update() nodes once tree visibility changes.

I hope to find a better answer at some point, but this is what I've got so far.

by (78 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.