I tested the project, and yeah, setting scroll_horizontal
is not acting like I would expect. It seems that no matter what value you set it to in _ready
, it doesn't apply. I think this is a bug, but I do not have enough experience with the ScrollContainer node to say for sure. At very least, it is not how I would expect the node to behave.
However, I found out how you can fix the issue! Just add yield(get_tree(), "idle_frame")
to _ready
before any of the other code, and it works as expected. Here's the code I used in _ready
:
func _ready():
yield(get_tree(), "idle_frame");
print("Read value:", Global.scroll)
print("Previous scroll:", scroll_horizontal)
scroll_horizontal = Global.scroll
print("After scroll:", scroll_horizontal)
With Global.scroll
set to 500
, it yields the expected result. Knowing this, I'm wondering if the issue with setting the horizontal_scroll
in _ready
is that, without a yield, the ScrollContainer is not fully initialized and therefore overrides any attempt to set the horizontal scroll property.
Regardless, hopefully adding a yield statement should fix the issue! :smile: