+1 vote

Hi, I have got a ScrollContainer with a VBoxContainer child node and some buttons are children of that. The scrolling works perfecly fine. But how can I scroll to a specific child of the VBoxContainer? I'm using C#.

in Engine by (22 points)

1 Answer

+1 vote

Assuming that you have a fix button height, you could calculate the scroll position like this:

var scrollPosition = buttonIndex * buttonHeight;

And set the ScrollVertical property on your ScrollContainer:

scrollContainer.ScrollVertical = scrollPosition;

If you have spacing between the items, you could use the GetConstant of the VBoxContainer with the separation parameter to get it:

var itemSpacing = vBoxContainer.GetConstant("separation");
var scrollPosition = buttonIndex * buttonHeight + buttonIndex * itemSpacing;
by (148 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories