I’m having an issue with drawing a large number of labels on the screen (with the legacy GUI).
I have about 10000 points in world space, each one having a label drawn only on repaint event:
foreach (var point in points)
{
var screenPos = Camera.main.WorldToScreenPoint(point.Position);
GUI.Label(new Rect(screenPos.x, Screen.height - screenPos.y, 100, 20), point.Text, LabelStyle);
}
It slows down entire application significantly. And I can have much more than 10000 points on the screen, which is even worse.
Is there a way to optimize it or do it other way around?
Aside from the technical issue, I just wanted to chime in and ask: Do you really need to display 10000 labels at the same time? Does it make sense? I’m not trying to stomp your design or anything, but perhaps you should take a step back and have a second thought.
You can just change it if you need to change it. Create a refrence to it and change the .text component. Destroying a lot of objects is not a good idea. You should look into pooling.
Yes, in some kind of applications (FE calculations, engineering, CAD, etc.) it makes sense to show 10000 labels at the same time - at least it is something that users expect (and they can still read something out of it).
At this is our case.
Initializing a large number of labels, pooling and reusing them is one way - but it still takes ages to create such number of objects. Tried it already I was also trying with GUIText and the result is the same.
I know that legacy GUI is not the best, but it seems it’s the best I can get so far (the fastest and without initialization of large number of objects).