Scrolling Dialogue UI smooth scroll gradually speeding up

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
xavibell
Posts: 10
Joined: Mon Jul 31, 2023 8:00 pm

Scrolling Dialogue UI smooth scroll gradually speeding up

Post 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.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Scrolling Dialogue UI smooth scroll gradually speeding up

Post 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.
User avatar
xavibell
Posts: 10
Joined: Mon Jul 31, 2023 8:00 pm

Re: Scrolling Dialogue UI smooth scroll gradually speeding up

Post 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;
            }
User avatar
xavibell
Posts: 10
Joined: Mon Jul 31, 2023 8:00 pm

Re: Scrolling Dialogue UI smooth scroll gradually speeding up

Post 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).
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Scrolling Dialogue UI smooth scroll gradually speeding up

Post 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?
User avatar
xavibell
Posts: 10
Joined: Mon Jul 31, 2023 8:00 pm

Re: Scrolling Dialogue UI smooth scroll gradually speeding up

Post by xavibell »

Looks like that solved it! Thanks for your help.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Scrolling Dialogue UI smooth scroll gradually speeding up

Post by Tony Li »

Glad to help!
Post Reply