Can I smoothly scroll VBoxContainer when child removed?

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

I have building a simple notification panel where message tiles appear in a list on the edge of the screen. When notifications expire they are removed from the list, and the other notifications move up to fill the space.

I implemented this with a VBoxContainer for the list of notifications with child scenes for each notification. Each child is a PanelContainer containing an HBoxContainer with TextureRect for an icon, plus a Label for the message. The child has a Timer to trigger deletion and an AnimationPlayer to fade it out (using modulate on the PanelContainer) before calling queue_free()

Everything works beautifully, except when a child notification tile is removed from the VBoxContainer, I would really like the visual effect of the remaining children smoothly scrolling up to fill the space, instead of jumping up when a child above it removed.

I tried animating the scale.y of each child as it is being removed so that it gets smaller vertically (after I fade it out). I cannot get the VBoxContainer to respond to this scaling - the VBoxContainer keeps the same vertical space for the child until it is fully removed, and then all the other children jump up. I also tried using _process to change scale.y instead of an animation, with the same result. I also tried forcing the child to emit item_rect_changed or resized signals during the scaling process, however this also did not work.

Is there any way I can make a VBoxContainer respond smoothly to one it’s children getting smaller in an animation?


I think changing the scale doesn’t affect rect_size. Can you try changing that instead? Containers override the scale of their children.

exuin | 2021-04-11 03:45

Thanks for replying exuin

I tried setting “rect_size”. I had not tried that before because I was not able to set that in the editor (it is set by the container). Setting “rect_size” in an animation does reduce the size of the child smoothly, which is good, however I got the same effect with the parent - the VBoxContainer does not update with the new size until the child is removed.

Based on your suggestion, I found a solution - I need to delete all the contents of the child, so it is just an empty container, and set “rect_min_size.y” and reduce that over time. It looks like changing this makes the parent VBoxContainer update smoothly.

Thanks very much!

AndyCampbell | 2021-04-11 13:17