How can I layout a node on the fly?

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


Im having problems arranging nodes created on-the-fly within a scene. They seem to be laid on-top of each other. The idea is to create a table of lines.

My ‘Main’ scene has this structure of nodes:


and my ‘LineScene’ has this structure of nodes:


My script preloads the LineScene and adds 10 new instances of this scene as children of VBoxContainer as follows:

extends Node2D

onready var line = preload("res://line_scene.tscn")

func _ready():
	for n in range(10):
		var new_line = line.instance()

I would like each line_scene instance to be arranged beneath the previous one automatically, as expected with a VBoxContainer.

What am I doing wrong? I have tried changing the size-flags of the line-scene nodes and the VBoxContainer separation but with no desired result.


:bust_in_silhouette: Reply From: rakkarage

enter image description here

u made scroll and vbox layout full rect? what is scroll rect size?

:bust_in_silhouette: Reply From: z80

It is min rect size property. Children of BoxContainer lay on top of each other if min rect size of the root most item of any of the children is left default (0, 0).