0
\$\begingroup\$

I have a UI panel with a scollrect inside, which I fill dynamically. It can only be moved vertically.

When filling this scollrect, the content jumps up and down for one frame, creating a weird look. When I check for the VerticalNormalizedPosition of the scrollrect after each added GameObject, it always tells me, the position is 1. When I check for the position in an Update method, it sometimes gives me a small rounding error. Instead of 1 it's somewhere between 0.9999995 and 0.9999998. The height of the content holder is less trhan 2000 units, whereas the jumps seems to be more than 2000*0.9999998.

enter image description here enter image description here

I tried to set the VerticalNormalizedPosition of the scrollrect to 1 every frame which didn't help. It also didn't help setting it after every newly added GameObject. Locking vertical scrolling also didn' help.

Is this soley a rounding error and I can't do anything about it, or is there a way to stop this jump from happening?

Here you can see the jump happening in 0.05 speed

\$\endgroup\$
3
  • \$\begingroup\$ You may want to try setting the position to 0 instead of 1, and reversing the direction of your stack if necessary. The trouble here is that every time you add more content to the view, you're changing what "1" means. When you only had a 200 px tall object in the view, 1 = 200 px. Then you add another one, and now 1 means 400 px, so the view has to scroll from the 200 px mark to 400 px to get to the new "1" you've assigned - and by default, it animates that scroll, rather than teleporting all at once. \$\endgroup\$
    – DMGregory
    Feb 10, 2021 at 14:12
  • \$\begingroup\$ @DMGregory I'm filling the contentHolder from top to bottom while I want to stay at the top. The contentHolder itself is top aligned at the parent. This way 1 should always be the same, shouldn't it? \$\endgroup\$
    – derfium
    Feb 10, 2021 at 14:33
  • \$\begingroup\$ No, as I described, the literal position meaning of "1" changes every time you add content. \$\endgroup\$
    – DMGregory
    Feb 10, 2021 at 14:50

1 Answer 1

0
\$\begingroup\$

If I'm understanding your issue correctly, you might want to try changing the scrollSensitivity in the inspector to a smaller number, because according to the Unity Documentation found on ScrollRects here:

[This controls] the sensitivity to scroll wheel and track pad events.

This should mean that if you change this to a smaller number, the ScrollRect's jumps should not be as large, due to decreased sensitivity.

\$\endgroup\$
5
  • \$\begingroup\$ I'm sorry, unlike i stated in the question, I don't use the ScrollView Component but the ScrollRect component. The ScrollRect doesn't have a verticalPageSize I think (correct me if I'm wrong). By saying I use a ScrollView, I meant the prebuilt "UI > Scrollview" element Unity provides. \$\endgroup\$
    – derfium
    Feb 10, 2021 at 14:28
  • \$\begingroup\$ @MarcelM. Ok, I edited my answer for ScrollRects. \$\endgroup\$ Feb 10, 2021 at 14:38
  • \$\begingroup\$ Thanks. After reading your initial answer I also tried setting it to 0 while filling. The jump still occours though. \$\endgroup\$
    – derfium
    Feb 10, 2021 at 14:41
  • \$\begingroup\$ @derfium Ok, can you add a small GIF showing what you mean to your answer? \$\endgroup\$ Feb 10, 2021 at 14:51
  • \$\begingroup\$ I added a link to a video. \$\endgroup\$
    – derfium
    Feb 10, 2021 at 15:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .