Scroll Container not working

Godot Version

Godot 4.2

Question

Hey,
Trying to add a scene/plugin that uses scrolling. But I can’t get it to scroll ever.
This is such a simple question, but I can’t find any kind of documentation for it.

Basically, my scene is this:

gocp

And the code is this

@tool
extends ScrollContainer
@export var dialog_lines: DialogLines
var num_lines:=0
func _ready() → void:
#$ScrollContainer.v_scroll_enabled=true
vertical_scroll_mode=ScrollContainer.SCROLL_MODE_SHOW_ALWAYS
for line in dialog_lines.lines:
print(line.text)

func _on_add_button_down() → void:
print(“New Line!”)
for line in dialog_lines.lines:

	var text_label = Label.new()
	var idx_label = Label.new()

	
	text_label.text = line.text
	idx_label.text = str(num_lines)
	var parentControl = Control.new()
	parentControl.size=Vector2(0,100)
	parentControl.position=Vector2(0,100+num_lines*75)
	
	$TopLevelControl.add_child(parentControl)

	parentControl.add_child(idx_label)
	parentControl.add_child(text_label)
	idx_label.position=Vector2(0,0)
	text_label.position=Vector2(20,0)
	if line.pic_str != null:
		print("Non-null!")
		var pic_area = TextureRect.new()
		var new_pic = load(line.pic_str)
		pic_area.texture = new_pic
		pic_area.expand_mode=TextureRect.EXPAND_FIT_WIDTH
		pic_area.stretch_mode=TextureRect.STRETCH_KEEP_ASPECT
		pic_area.size=Vector2(150,150)
		pic_area.position=Vector2(200,0)
		parentControl.add_child(pic_area)
	else:
		var pic_area = Container.new()
		parentControl.add_child(pic_area)

	num_lines += 1

pass # Replace with function body.

But no matter how often I add a line (by clicking the button) the scroll bar doesn’t scroll at all.

What’s the obvious thing I’m missing here?

Sorry to be a pain.

Here’s a pic of the scene when played: Ideally, I could use this as a plugin, but this is a typical play scene.

Use a Container like a VBoxContainer as the child of a ScrollContainer so it automatically grows when adding children. A plain Control won’t grow when you add children.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.