Hello everyone,
Im trying to show some values for every tile in my 3d game.
So I created one Text, which updates its position via the Camera.main.WorldToScreenPoint() function. So far so good. But I need about 5000 “Labels” for every tile in my game which drops the fps by 50 when moving, compared to only one label. I tried attaching all the labels as children to one gameobject, so that unity (in theory) only needs to calculate one Vector for all the labels but it doesnt improve the performance by much.
In comparison, If I have just one Text Object, with all the different information inside the text everythings fine. But I cant edit the textfield to display everything correctly so I still need to have everything in different Textobjects.
Does anyone have a good idea how to implement this without losing so much performance?
Thanks and greetings, squig
Edit: I guess the problem is, even if all the labels are all following the same parent, Unity calculates their position seperatly and that takes to much performance. I need a way that Unity treats them all as one entity when moving.
If you’re intending on rendering all that text simultaneously at runtime, you’ll have to get a bit creative. Unity UI elements have a lot of extra components on them that make them a bit resource-intensive, like raycast detection and such.
If it were me, I’d consider the full range of values you’d need to display. It seems you’re doing elevation or population or something, so let’s say it’s values between 0 and 10. Make a texture that has the values you need on it in evenly spaced tiles. Something like this:
Then make a mesh that’s just a simple square, and map its UV to only take up the top left spot, so that the face just says “0” on it. This mesh sit barely above the surface of your hex tile, and when you need to set a different value, you shift the UV the correct amount so that another number is shown instead. You’ll probably want the background to be transparent, and the text to be white so you can make it a different color in the material instance, if needed.
You could also try just using a Sprite object and doing the same thing, but with separate sprites defined for each letter. That would probably be simpler to implement.