Page 1 of 1

Scrolling Dialogue UI smooth scroll gradually speeding up

Posted: Fri Aug 25, 2023 4:12 am
by xavibell
Hi,

I have a scrolling dialogue UI that will smoothly scroll down as more text appears. The issue is that as a conversation progresses and more and more text is put into the subtitle text box, the smooth scroll effect for some reason speeds up to the point that it becomes instant. Obviously, I'd prefer it to stay the exact same speed at all times, but unfortunately I have no clue how to make that happen.

If it matters, I'm calling CheckScrollBarWithResetValue() from the UIScrollbarEnabler script using the On Begin() function of the TextMesh Pro Typewriter Effect script.

Thanks.

Re: Scrolling Dialogue UI smooth scroll gradually speeding up

Posted: Fri Aug 25, 2023 8:32 am
by Tony Li
Hi,

You could borrow the smooth scrolling code from SMSDialogueUI.cs. Grab the ScrollToBottom() and ScrollToBottomCoroutine() methods and its corresponding variables, and use them in your own script.

Re: Scrolling Dialogue UI smooth scroll gradually speeding up

Posted: Sat Aug 26, 2023 12:19 am
by xavibell
Thanks for the reply.

That works, but with one issue. It seems that when the scroll content becomes larger and larger, it will only scroll smoothly for a brief period before quickly jumping down to the bottom.

I fixed this by making a slight change to the ScrollToBottomCoroutine while loop. Initally the while loop would just exit once scrollRect.verticalNormalizedPosition was less than 0.01, but I've multiplied it by the ratio so that it changes based on the size of the scroll content. I'm not sure if this is a bad idea or not, but it seems to work well enough for now.

Code: Select all

var ratio = scrollRectHeight / contentHeight;
var timeout = Time.time + 10f; // Avoid infinite loops by maxing out at 10 seconds.
            
while (scrollRect.verticalNormalizedPosition > 0.01f * ratio && Time.time < timeout)
            {
                var newPos = scrollRect.verticalNormalizedPosition - scrollSpeed * Time.deltaTime * ratio;
                scrollRect.verticalNormalizedPosition = Mathf.Max(0, newPos);
                yield return null;
            }

Re: Scrolling Dialogue UI smooth scroll gradually speeding up

Posted: Sat Aug 26, 2023 4:23 am
by xavibell
I tell a lie. That didn't quite fix it. I just wasn't looking close enough. I'm using the ScrollToBottom() function as you've suggested, but it still seems to have the exact same problem of the smooth scroll speed getting faster the longer the conversation is (or the the larger the height of the scroll transform is).

Re: Scrolling Dialogue UI smooth scroll gradually speeding up

Posted: Sat Aug 26, 2023 2:30 pm
by Tony Li
Hi,

The code in ScrollToBottomCoroutine() determines how fast it will need to scroll in order to scroll the entire content over scrollSpeed (default 5 seconds). You might want to change that computation so that it determines how fast to scroll based on the content height instead.

If that doesn't help, can you send a reproduction project to tony (at) pixelcrushers.com?

Re: Scrolling Dialogue UI smooth scroll gradually speeding up

Posted: Sun Aug 27, 2023 5:10 am
by xavibell
Looks like that solved it! Thanks for your help.

Re: Scrolling Dialogue UI smooth scroll gradually speeding up

Posted: Sun Aug 27, 2023 8:49 am
by Tony Li
Glad to help!