From 9d04086451545fb744fbfce8639e8e66327a65c0 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Fri, 3 Dec 2021 19:07:01 -0500 Subject: [PATCH] Document how to autoscroll ScrollContainer. It is not uncommon to want to scroll to the most recently added child of a ScrollContainer (e.g. a chat box or activity log). This is a little tricky, since `ensure_control_visible` will not work on a node on the same frame as you add it. Let's at least document that you need to wait until the next frame. Relates to https://github.com/godotengine/godot-proposals/issues/3629. Co-authored-by: Yuri Sizov --- doc/classes/ScrollContainer.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/classes/ScrollContainer.xml b/doc/classes/ScrollContainer.xml index 976c32c2435..711e028a678 100644 --- a/doc/classes/ScrollContainer.xml +++ b/doc/classes/ScrollContainer.xml @@ -16,6 +16,12 @@ Ensures the given [code]control[/code] is visible (must be a direct or indirect child of the ScrollContainer). Used by [member follow_focus]. + [b]Note:[/b] This will not work on a node that was just added during the same frame. If you want to scroll to a newly added child, you must wait until the next frame using [signal SceneTree.process_frame]: + [codeblock] + add_child(child_node) + await get_tree().process_frame + ensure_control_visible(child_node) + [/codeblock]