ScrollContainer added elements from script - add from bottom

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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?

:bust_in_silhouette: 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