Page 1 of 1

Accumulate text causes jitter

Posted: Tue Aug 29, 2023 10:29 pm
by xavibell
Hi, I'm back with more problems.

The issue this time is to do with the ScrollToBottom() function I've grabbed from the SMS Dialogue UI to use in my Scrolling Dialogue UI. Since all my dialogue is just written to a single text box with the Accumulate Text setting, I've had to keep the Max Lines value relatively low for performance reasons. In doing so, when the dialogue becomes long enough that it starts deleting the oldest line, there's occasionally a very brief jitter (like a single frame) where text moves out of position, and the ScrollToBottom() function will only work some of the time. I imagine this is something to do with the fact that sometimes the removed lines of text are longer than the added lines, but I wouldn't have a clue how to solve this. I probably haven't done a great job explaining the issue, so I made this video showcasing it.



Don't mind the gibberish text. At the start, you'll see how the text scroll is supposed to work. When it reaches the point where all the text goes white (the max line limit is reached), the issue I've been talking about appears. Sometimes it scrolls, sometimes it'll just jump to the bottom, or jitter.

Any fixes or work arounds would be appreciated.

Re: Accumulate text causes jitter

Posted: Wed Aug 30, 2023 11:44 am
by Tony Li
Just brainstorming -- Are you accumulating text in a single string like the WRPG and Runic dialogue UIs do? Or are you instantiating individual subtitle panel instances for each line like SMSDialogueUI does? If you're accumulating text in a single strong, you could set Max Lines very high (e.g., infinity). When line count gets high, you could go through the string and replace all the upper lines with blank lines. So in place of this:

Code: Select all

AAA
BBB
CCC
DDD
EEE
FFF
GGG
You could replace AAA and BBB with blank lines:

Code: Select all

 
 
CCC
DDD
EEE
FFF
GGG
It's a little tricky because you'll need to check TextMeshPro to determine where the line breaks for automatic word wrapping occur and include those as blank lines.

This should keep the accumulated text at the same height to prevent jumps.

Alternatively, you could adjust your scroll coroutine so it doesn't jump by determining what the minimum value needs to be to prevent the jump and then only adjusting it from there.

Re: Accumulate text causes jitter

Posted: Wed Aug 30, 2023 8:53 pm
by xavibell
Thanks for the reply.

All the subtitles are accumulated in the same string. Your blank line idea sounds like it could work, and it seems you were definitely right about it being tricky. I won't ask you to too much about how to do it, but could you point me in the right direction? I've done some searching and found very little information so far.

Re: Accumulate text causes jitter

Posted: Wed Aug 30, 2023 10:16 pm
by Tony Li
You could make a subclass of StandardUISubtitlePanel and override the SetSubtitleTextContent() method. You'll need to add two variables to your subclass:
  • A list of the line counts of subtitles that are currently in the accumulated text string.
  • A count of newlines that have been added to the accumulated string.
Override the ClearText() method to reset both of these values.

In the SetSubtitleTextContent() method, if you're at max lines, delete all leading newlines and the next full line. Remove the first element from the list of line counts (since it's no longer shown in the accumulated string), and add it to the count of newlines. Then add all of those newlines to the text. Set numAccumulatedLines to (maxLines - 1).

Then set the subtitle text's text value to only the current subtitle.formattedText.text. Call subtitleText.ForceMeshUpdate(true) to get it to determine how it will lay out the text. Add subtitleText.textInfo.lineCount to the list of line counts.

Then call the base.SetSubtitleTextContent(subtitle) method.

---

Alternatively, you could use the version of the TextlineDialogueUI included in the Textline package on the Dialogue System Extras page that works with Enhanced Scroller. This does an infinite scroll without having to limit it to Max Lines.

---

Or, if you don't want to fiddle with existing code, you could handle the UI completely yourself. As long as it implements the IDialogueUI C# interface, you can assign it to the Dialogue Manager's Dialogue UI field.