+1 vote

For example, I have a GridContainer inside a ScrollContainer.
In _ready() I add items into the GridContainer (a list of level buttons).

I need to scroll the ScrollContainer so the last level that the player reached is visible.
So I need to get the position of the button for the level and then update the ScrollContainer scroll_vertical value.

Using a simple yield(get_tree(), "idle_frame") does not work.

Running it once in _process() does not work.
However if I leave it running for all frames in _process(), then it does work. (But then the ScrollContainer is stuck at that position.)

It seems like it takes multiple frames for it to get the final positions.
Also, I'm not sure, but it may also be related to visibility somehow. Ie. if the thing is not visible on screen yet (visibility of itself or an ancestor is false), then it will not get correct positions yet.

This makes it very frustrating when you need to programmatically position things.

Is there a method that can just be called to get everything into position so I can do programmatic positioning?

As it is, I don't know how to implement this.

in Engine by (253 points)

Please log in or register to answer this question.

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.