Set Scroll Container to bottom

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

Hey All,

I have a script that adds labels into a VBox that has a parent of ScrollContainer. Every time a label is entered I want to set the scroll bar to the bottom.& Not the top.

How would I work out where the bottom?

Cheers

:bust_in_silhouette: Reply From: njamster

Check out this question.

:bust_in_silhouette: Reply From: skitzoid

Jmbiv’s youtube video explains this really well.

  • You can use the changed signal from the ScrollContainer’s child ~ VScrollBar
  • Connect it to a function to scroll to the VScrolBar’s max_value
  • But only when the max_value has changed
  
  func _ready() -> void:
     scrollbar.connect("changed", self, "scroll_to_bottom")
     max_scroll = scrollbar.max_value 

  func scroll_to_bottom(): 
	if max_scroll != scrollbar.max_value:
		max_scroll = scrollbar.max_value
		scroll_container.scroll_vertical = scrollbar.max_value