# How to get scrollbar to automatically scroll to bottom?

**URL:** <https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013>\
**Category:** Help\
**Tags:** godot-4, gdscript\
**Created:** [July 26, 2024, 10:45am UTC](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013 "2024-07-26T10:45:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![0bladesilver](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/0/a3d4f5/32.png) [@0bladesilver](https://forum.godotengine.org/u/0bladesilver)\
**Post date:** [July 26, 2024, 10:45am UTC](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013/1 "2024-07-26T10:45:23Z")

</div>

Godot 4.2 Stable

The game I’m working on is heavily menu-based, and I’m trying to find a way to get the scroll container to scroll to the bottom of its contents via script whenever a new menu pops up. Looking at the other answers on here talks about using functions that don’t appear to exist anymore. Anything associated with .value and max\_value don’t work, although max value shows up as an integer when printed. What exactly am I missing?

---

<div class="post-metadata">

**Author:** ![coderjo](https://forum.godotengine.org/user_avatar/forum.godotengine.org/coderjo/32/25889_2.png) [@coderjo](https://forum.godotengine.org/u/coderjo)\
**Post date:** [July 26, 2024, 11:41am UTC](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013/2 "2024-07-26T11:41:32Z")

</div>

Modify it via `ScrollContainer.scroll_vertical` instead of changing the `ScrollBar` would be fine.

---

<div class="post-metadata">

**Author:** ![0bladesilver](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/0/a3d4f5/32.png) [@0bladesilver](https://forum.godotengine.org/u/0bladesilver)\
**Post date:** [July 26, 2024, 4:59pm UTC](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013/3 "2024-07-26T16:59:04Z")

</div>

I’m afraid this doesn’t work either. I tried multiple ways of using ScrollContainer, including set\_deferred and across multiple scripts. I either get error messages or nothing happens.

Strangely, when I attach the function to a button it works perfectly, but I can’t seem to get it to automatically go. I’ve even tried to use signals to relay the command to a custom script attached to the container, but nothing seems to do the trick.

---

<div class="post-metadata">

**Author:** ![0bladesilver](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/0/a3d4f5/32.png) [@0bladesilver](https://forum.godotengine.org/u/0bladesilver)\
**Post date:** [July 26, 2024, 5:10pm UTC](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013/4 "2024-07-26T17:10:20Z")

</div>

Update: I just added a print to the signal function and it appears to be calling correctly. It’s almost as if something is overwriting the scroll value after the function is called. Considering I have no other functions attached to the scroll value, any ideas on possible culprits?

---

<div class="post-metadata">

**Author:** ![zdrmlpzdrmlp](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/z/5daacb/32.png) [@zdrmlpzdrmlp](https://forum.godotengine.org/u/zdrmlpzdrmlp)\
**Post date:** [July 26, 2024, 5:14pm UTC](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013/5 "2024-07-26T17:14:41Z")

</div>

> [@0bladesilver](#):
>
> I’m trying to find a way to get the scroll container to scroll to the bottom of its contents via script whenever a new menu pops up.

well um, just set it to 9999 or really get the max scroll value and set\_deffered the scroll\_vertical of the scrollcontainer to that value

how to get the max scroll value?

```auto
the_scrollcontainer.get_v_scroll_bar().max_value

```

how to set the scroll\_vertical to max value?

```auto
the_scrollcontainer.set_deferred("scroll_vertical", the_scrollcontainer.get_v_scroll_bar().max_value)

```

---

<div class="post-metadata">

**Author:** ![0bladesilver](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/0/a3d4f5/32.png) [@0bladesilver](https://forum.godotengine.org/u/0bladesilver)\
**Post date:** [July 26, 2024, 5:24pm UTC](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013/6 "2024-07-26T17:24:13Z")

</div>

As I said, I tried set\_deferred already. My function is calling properly, but something else appears to be overwriting the value after the function sets it.

I’ve come across a workaround by using a timer set for .01 seconds into runtime.

---

<div class="post-metadata">

**Author:** ![zdrmlpzdrmlp](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/z/5daacb/32.png) [@zdrmlpzdrmlp](https://forum.godotengine.org/u/zdrmlpzdrmlp)\
**Post date:** [July 26, 2024, 5:25pm UTC](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013/7 "2024-07-26T17:25:08Z")

</div>

have you tried tweening the value to that?

---

<div class="post-metadata">

**Author:** ![0bladesilver](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/0/a3d4f5/32.png) [@0bladesilver](https://forum.godotengine.org/u/0bladesilver)\
**Post date:** [July 26, 2024, 5:37pm UTC](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013/8 "2024-07-26T17:37:38Z")

</div>

This solution works as well, and without the need for an extra node. Much appreciated

---

<div class="post-metadata">

**Author:** ![coderjo](https://forum.godotengine.org/user_avatar/forum.godotengine.org/coderjo/32/25889_2.png) [@coderjo](https://forum.godotengine.org/u/coderjo)\
**Post date:** [July 27, 2024, 2:57am UTC](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013/9 "2024-07-27T02:57:50Z")

</div>

> [@zdrmlpzdrmlp](#):
>
> have you tried tweening the value to that?

> [@0bladesilver](#):
>
> I’ve come across a workaround by using a timer set for .01 seconds into runtime.

You just remind me of the scene tree timer:

```gdscript
await get_tree().create_timer(.01).timeout
the_scrollcontainer.set_deferred("scroll_vertical", the_scrollcontainer.get_v_scroll_bar().max_value)

```

or

```gdscript
get_tree().create_timer(.01).timeout.connect(
    func () -> void:
        the_scrollcontainer.set_deferred("scroll_vertical", the_scrollcontainer.get_v_scroll_bar().max_value)
)

```

---

<div class="post-metadata">

**Author:** ![wyattbiker](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/w/87869e/32.png) [@wyattbiker](https://forum.godotengine.org/u/wyattbiker)\
**Post date:** [July 27, 2024, 5:07am UTC](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013/10 "2024-07-27T05:07:54Z")

</div>

Just put this in your ScrollContainer. Assuming you are adding some labels to the VBoxContainer when a button is pressed.

```auto
extends ScrollContainer

var start_text=100

func _enter_tree():
	set_deferred("scroll_vertical", 10000)

func _on_button_pressed():
	var label=Label.new()
	label.horizontal_alignment=HORIZONTAL_ALIGNMENT_CENTER
	start_text += 10
	label.text = str(start_text)
	$VBoxContainer.add_child(label)
	call_deferred("update_scroll")
	pass # Replace with function body.

func update_scroll():
	set_deferred("scroll_vertical", 10000)

```

 ![image](https://forum.godotengine.org/uploads/default/original/3X/7/c/7c87b18ead832f33a00d539c4e3dfa9086ef70cd.png)

---

<div class="post-metadata">

**Author:** ![ernest.o.cooper](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/e/7993a0/32.png) [@ernest.o.cooper](https://forum.godotengine.org/u/ernest.o.cooper)\
**Post date:** [December 16, 2024, 6:17pm UTC](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013/11 "2024-12-16T18:17:57Z")

</div>

I’m losing my mind. I’m using 4.3, using ChatGPT, I cannot get the scrollbar to go to the end.

I’m using

```
	await get_tree().create_timer(1).timeout
	scroll_container.set_deferred("scroll_vertical", 10000)

```

does not work. why is this so hard.

---

<div class="post-metadata">

**Author:** ![Mike\_from\_TRIC](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@Mike\_from\_TRIC](https://forum.godotengine.org/u/Mike_from_TRIC)\
**Post date:** [December 23, 2024, 7:11am UTC](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013/12 "2024-12-23T07:11:26Z")

</div>

Here’s the function I used in my script to solve this problem. I’m taking a `LineEdit`’s submitted signal, making a new `Label` (of a custom extended class, `CommandEntryLabel`), assigning the submitted text to it, and appending it into a `VBoxContainer` within a `ScrollContainer`.

My best guess about what’s going on is that you tell it to scroll to what the maximum value is, but then a split second later it updates what that max value ACTUALLY is, which makes it appear like it didn’t really scroll to the bottom.

I hope this helps!

```gdscript
func _on_command_entry_text_submitted(command_text: String) -> void:
	var new_entry: CommandEntryLabel = CommandEntryLabel.new()
	new_entry.text = command_text
	%HistoryEntries.add_child(new_entry)
	%CommandEntry.text = ''
	
	# Waiting a split second after adding the text allows the program to catch up and properly
	# scroll all the way to the bottom. It's frustrating that I have to even do this hack,
	# but... here we are.
	get_tree().create_timer(.01).timeout.connect(
		func () -> void:
			%CommandHistory.scroll_vertical = %CommandHistory.get_v_scroll_bar().max_value
	)

```

---

<div class="post-metadata">

**Author:** ![INKnight](https://forum.godotengine.org/user_avatar/forum.godotengine.org/inknight/32/64136_2.png) [@INKnight](https://forum.godotengine.org/u/INKnight)\
**Post date:** [January 29, 2025, 12:56am UTC](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013/13 "2025-01-29T00:56:08Z")

</div>

```auto
texts_container.add_child(message_scene)
await to_signal(RenderingServer.singleton, RenderingServer.FRAME_POST_DRAW)
texts_container.get_parent().get_parent().scroll_vertical = 10000

```

This is how I did it. Waiting for the next frame works well

---

<div class="post-metadata">

**Author:** ![jamonholmgren](https://forum.godotengine.org/user_avatar/forum.godotengine.org/jamonholmgren/32/25256_2.png) [@jamonholmgren](https://forum.godotengine.org/u/jamonholmgren)\
**Post date:** [February 16, 2025, 10:45pm UTC](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013/14 "2025-02-16T22:45:07Z")

</div>

Another option is to do _two_ call\_deferred – in other words, wait two process frames.

```gdscript
func post_message(msg: String):
  # ... post your message
  call_deferred("scroll_chat_to_bottom_1")

func scroll_chat_to_bottom_1():
  call_deferred("scroll_chat_to_bottom_2")

func scroll_chat_to_bottom_2():
  scroll_container.scroll_vertical = scroll_container.get_v_scroll_bar().max_value

```

This is also really low-cost, as it’s just a normal (efficient) call\_deferred, twice, rather than spawning a timer or awaiting a signal.

---

<div class="post-metadata">

**Author:** ![flyte](https://forum.godotengine.org/user_avatar/forum.godotengine.org/flyte/32/47550_2.png) [@flyte](https://forum.godotengine.org/u/flyte)\
**Post date:** [April 8, 2025, 2:56pm UTC](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013/15 "2025-04-08T14:56:13Z")

</div>

This is a nice, simple solution. I’ve nested the functions to avoid the confusing \_1 and \_2 funcs:

```auto
func scroll_to_bottom() -> void:
	var stb := func():
		scroll_vertical = get_v_scroll_bar().max_value
	stb.call_deferred()

func post_message(str: String):
	# ... post your message
	scroll_to_bottom.call_deferred()

```

Depending on the compiler optimisations, this may be slower if it’s creating a new function each time it’s called.

---

<div class="post-metadata">

**Author:** ![brandonromano](https://forum.godotengine.org/user_avatar/forum.godotengine.org/brandonromano/32/52001_2.png) [@brandonromano](https://forum.godotengine.org/u/brandonromano)\
**Post date:** [June 22, 2025, 3:49pm UTC](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013/16 "2025-06-22T15:49:43Z")

</div>

Further riffing on the ideas shared by @jamonholmgren & @flyte:

You could recursively defer call the same function here:

```gdscript
func scroll_to_bottom_in_n_frames(n: int):
	if n <= 0:
		@warning_ignore("narrowing_conversion")
		scroll_vertical = get_v_scroll_bar().max_value
	else:
		scroll_to_bottom_in_n_frames.call_deferred(n - 1)

```

I ran into a similar problem described in this thread, except I had to wait for 3 frames for the sizing to propagate to my scroll container, due to how I’m using a few nested containers between the list I’m appending to and the scrolling container.

```auto
scroll_to_bottom_in_n_frames(3)

```

---

<div class="post-metadata">

**Author:** ![k3m](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/k/cc9497/32.png) [@k3m](https://forum.godotengine.org/u/k3m)\
**Post date:** [August 22, 2025, 3:25pm UTC](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013/17 "2025-08-22T15:25:16Z")

</div>

So by playing around with a few of the suggestions here (thank you all, this thread is a life-saver lol) I ended up with this for making a DMs-style chatbox:

```auto
func new_message(message) :
    var message_instance = individualChats.instantiate()
    message_instance.set_data(message)
    $ScrollContainer/VBoxContainer.add_child(message_instance)

func update_scroll() :
    var max_scroll = $ScrollContainer.get_v_scroll_bar().max_value
    $ScrollContainer.set_deferred("scroll_vertical", max_scroll)

func _on_action_to_send_message() :
    var msg = "Hello World"
    new_message(msg)
    update_scroll.call_deferred()

```

Not sure if this only works because it’s instantiating another scene for the individual messages, but it might be worth testing without that and seeing if something like this:

```auto
func update_scroll() :
    var max_scroll = $ScrollContainer.get_v_scroll_bar().max_value
    $ScrollContainer.set_deferred("scroll_vertical", max_scroll)

func menu_popup() : 
    # insert code here
    update_scroll.call_deferred()

```

would still have the same desired effect!

---

<div class="post-metadata">

**Author:** ![taska](https://forum.godotengine.org/user_avatar/forum.godotengine.org/taska/32/35242_2.png) [@taska](https://forum.godotengine.org/u/taska)\
**Post date:** [October 9, 2025, 7:29pm UTC](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013/18 "2025-10-09T19:29:48Z")

</div>

Is this a bug? If yes, has anyone reported it yet? 😅 This feels like a really weird and hacky solution for something as basic as “scrolling to bottom in a node specifically designed for scrolling”

For future reference… here’s one of the solutions from above but in C#:

```auto
public void Update()
{
    // Add nodes, etc...
    CallDeferred("UpdateScroll");
}

private void UpdateScroll() {
    ScrollContainer.SetDeferred("scroll_vertical", 99999);
}

```

---

<div class="post-metadata">

**Author:** ![emmanuel](https://forum.godotengine.org/user_avatar/forum.godotengine.org/emmanuel/32/58876_2.png) [@emmanuel](https://forum.godotengine.org/u/emmanuel)\
**Post date:** [October 11, 2025, 1:59pm UTC](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013/19 "2025-10-11T13:59:22Z")

</div>

Well, that’s when AI really helps. I asked Chat-GPT to improve your code, and here’s the result:

```auto
func scroll_to_bottom() -> void:
	await get_tree().process_frame
	scroll_container.scroll_vertical = int(scroll_container.get_v_scroll_bar().max_value)

```

In my case, I’m using it after updating the text.

```auto
if result != "":
		history_label.text += "\n" + result
		scroll_to_bottom()

```

The key here is this: `await get_tree().process_frame`; which makes the script wait for 1 full frame.

Thank you, jamonholmgren, and all!

---

<div class="post-metadata">

**Author:** ![MegaNerk](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/m/cab0a1/32.png) [@MegaNerk](https://forum.godotengine.org/u/MegaNerk)\
**Post date:** [April 10, 2026, 8:50am UTC](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013/20 "2026-04-10T08:50:32Z")

</div>

Years later, spent all night trying to solve this problem with some help from this thread. This is a custom ScrollContainer which keeps the scrollbar pinned to the bottom as it’s content is changed, but only when the scrollbar was touching the bottom before the content was changed. Those who come later may find it useful. Made in Godot 4.6.2.

```auto
extends ScrollContainer

## Scroll container that stays at bottom if new element is added and scroll was at bottom
class_name PinDownScrollContainer

## [code]true[/code] if scrollbar is at bottom
var _pinning : bool = false 

func _init():
    get_v_scroll_bar().changed.connect(_on_scroll_bar_changed)
    get_v_scroll_bar().value_changed.connect(_on_scroll_bar_value_changed)

## When scroll bar size changes (element count changed), keep scroll at bottom is pinning [code]true[/code]
func _on_scroll_bar_changed():
    if _pinning:
        _scroll_to_bottom.call_deferred()

## When scroll bar is scrolled, set [code]pinned[/code] to [code]true[/code]
func _on_scroll_bar_value_changed(x):
    _pinning = (scroll_vertical >= get_v_scroll_bar().max_value-get_v_scroll_bar().page-1.0)

## Scroll to the bottom
func _scroll_to_bottom():
    scroll_vertical = get_v_scroll_bar().max_value

```

[Next page](https://forum.godotengine.org/t/how-to-get-scrollbar-to-automatically-scroll-to-bottom/74013.md?page=2)
