- Home /
What's the best way to display large amount of UI text?
I have some issues with the Unity UI Vertex cap of 65535 per canvas. First of all, I'm still on Unity 4.6. In case anything changed to the vertex cap limit since then, please let me know.
Otherwise, what's the best practices to show a combat log, which can have quite some text? I already run into the vertex cap after ~20 lines of text, which is not a whole lot. It seems like it's very unnecessary that UI text needs that many vertices to be displayed.
I'm using a scroll rect as well, but after about 20 messages, I get "Canvas element contains more than 65535 vertices". The messages are not that long (About 30 characters each with an outline). And I don't need more than 50 messages, but 20 is just not enough.
I'll try to upgrade to the latest Unity version and see whether that fixes the issue. $$anonymous$$aybe they've reduced the amount of vertices for text.
Answer by Dibbie · Nov 20, 2015 at 07:12 PM
I would then say it has changed a lot? Cause one of my game projects has a combat log embedded into the chat log too (I know, bad combo...), and it reports EVERYTHING, from server announcements, new matches, players talking, AI talking, location, and general combat, the first 30 seconds, is somewhere like 300 and something lines, and they are detailed... (and color coded)
But I simulate a "scroll rect" as well. So my text is displayed inside a panel, which is inside a "container" (which is actually a panel), with a mask, and scroll bar.
But I also have a "threshold", after 2000 messages, the first message gets deleted, so my "log" only ever shows the most recent 2000 messages, after that, its gone. So it depends on how far you want to keep messages too, if your okay with having it eventually cleared, you can add code to start clearing the first line of this log, after you reach a certain line count, by just putting every single message into 1 large array, and adding every new line, as the next free element in the array, then after the array is full, clear the first element, move everything up by 1, add the new text in.
Probably a pretty "bad" way to do it, but I never experienced any problems with it before, and I was using Windows 7 on a crappy like 2 GB RAM PC, full of viruses and just slow as crap... And it was fine with no lag due to my code...
Did you use one text component or one text component for each line?
You could use one text component and enable rich text. That way you could flag each line with a tag, or anything else. $$anonymous$$ore info here
I feel, that I'm doing something wrong. While Unity is not crashing anymore, if I add 5 messages with black outline to a scroll rect, it adds ~20k verts. 2k comes from the actual text and about 18k from the outline.
If I scroll with the rect it's actually lagging pretty hard.
I know unity's latest UI is not that performance friendly, have you tried changing the font import settings from "Dynamic" to "Ascii .." ? Dynamic font's need to be recalculated everytime, which for example on iOS creates HUGE laggspikes
I just tried that now, but it doesn't help. The result is the same. But if I disable the outline, everything seems to work fine.
Answer by gresolio · Jul 27, 2016 at 08:32 PM
A simple but quite effective solution: http://forum.unity3d.com/threads/dynamic-scrolling-text-support.360026/
In short: use one "Text" component per line (or more, up to limit), and use new "RectMask2D" instead of "Mask". "Vertical Layout Group" and "Content Size Fitter" will help you to place the items correctly. "Layout Element" would be useful to set the minimum height of the item. That's all. Good enough for large amount of text with scroll support :)
My small project to test the idea: https://github.com/gresolio/Unity_UiTextLimit