![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | lxknvlk |
Currently when adding elements with add_child() they are added from top. I want to add from bottom. How do i make this?
![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | lxknvlk |
Currently when adding elements with add_child() they are added from top. I want to add from bottom. How do i make this?
![]() |
Reply From: | jgodfrey |
One way would be to insert a child (at the bottom of the tree) via add_child
and then immediately move it to the top via move_child
. Here’s an example;
extends CanvasLayer
func _ready():
var vb = $ScrollContainer/VBoxContainer
for i in range(10):
var btn = Button.new()
btn.text = "Button" + str(i)
vb.add_child(btn) # insert the new node at the bottom
vb.move_child(btn, 0) # move the just-inserted node to the top