I'm outputting Labels and Buttons to a ScrollContainer from a script. The structure is:

ScrollContainer
.... VBoxContainer
.... .... VBoxContainer
.... .... GridContainer

Everything works properly, except that I want to automatically scroll down when items are output so that the last added items are visible.

I read that the way to do this is: $ScrollContainer.scroll_vertical = int($ScrollContainer.get_v_scrollbar().max_value)

But it doesn't work. Manual scrolling is required to scroll down.

I've tried some variations, but can't change the vertical scroll position from the script.

I've tried adding $ScrollContainer.update() after the statement above, and in the _process() function, but it didn't help.

Any ideas?

As expected, a few minutes after I made the above post, I found a solution.

I attached a script to ScrollContainer with contents:

extends ScrollContainer

func _draw() -> void:
	scroll_vertical = int(get_v_scrollbar().max_value)

And it works. :grin:

The above solution had the unwanted side effect of disabling manual scrolling. I resolved that, but it's complicated, and I won't elaborate unless someone asks for details.

9 months later

Could you elaborate as to how you solved this? For me every time I try to find away around the disabled manual scrolling it just sets itself back to the top.

Before I post my solution, I'll post this alternate solution that I found but didn't try. If it doesn't work, let me know and I'll post my solution, which is more complicated.

		onready var ScrollContainer: ScrollContainer = $ScrollContainer
		onready var ScrollBar: ScrollBar = ScrollContainer.get_v_scrollbar()
		onready var scroll_bar_max_value: int = ScrollBar.max_value

		func _ready() -> void:
			# Reference: https://docs.godotengine.org/en/stable/classes/class_range.html#signals
			ScrollBar.connect("changed", self, "on_scroll_bar_changed")

		func on_scroll_bar_changed() -> void:
			if scroll_bar_max_value != ScrollBar.max_value:
				scroll_bar_max_value = ScrollBar.max_value
				ScrollContainer.scroll_vertical = scroll_bar_max_value

Source: https://www.reddit.com/r/godot/comments/lvabri/how_to_make_scrollcontainers_autoscroll_to_the/

I think you can just do this:

get_v_scrollbar().ratio = 1.0

You can call that in any function (just once, it doesn't need to be on draw).

a year later