Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Labels / Icons in 3d Game

Discussion in 'Getting Started' started by Squig2, Feb 6, 2021.

  1. Squig2

    Squig2

    Joined:
    Jul 24, 2014
    Posts:
    5
    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.



     

    Attached Files:

    Last edited: Feb 6, 2021
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,510
    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:
    upload_2021-2-5_21-23-50.png

    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.
     
    JoeStrout likes this.
  3. Squig2

    Squig2

    Joined:
    Jul 24, 2014
    Posts:
    5
    Thank you I need to check out if this brings better performance
    greetings