Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Unity UI Many Canvases - Render Mode World Space

Discussion in 'UGUI & TextMesh Pro' started by AntonBaranov, Feb 22, 2019.

  1. AntonBaranov

    AntonBaranov

    Joined:
    Mar 7, 2015
    Posts:
    11
    Hey, guys!
    I have a scene where I need to instantiate many prefabs (around 5k-10k). I have prefab hierarchy like this:
    • GameObject (Transform, BoxCollider, Script)
      • GameObject (Transform, SpriteRenderer)
      • GameObject (RectTransform, Canvas (World space), CanvasScaler)
        • GameObject (RectTransform, CanvasRenderer, TextMeshProUGUI)
      • GameObject (Transform, SpriteRenderer)
    The problem is draw calls count, because each Canvas is a one draw call. I can't use one Canvas for all objects because sometimes I need to interact with objects (select, drag and so on). Obvious, that when I zoom in there are not so many draw calls, but when I zoom out... it awful.
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Hi @AntonBaranov

    If you don't need world space aligned panels over units (as you use sprites...unless it's sprites in 3d world or something), why not put the panels/bars/whatever you have in Screen space canvas then you can have as many panels as you need in one canvas.

    You could do a world to screen space conversion and then use that to place panels relative to units. See these threads:
    https://forum.unity.com/threads/create-ui-health-markers-like-in-world-of-tanks.432935/
    https://forum.unity.com/threads/get-ui-placed-right-over-gameobjects-head.489464/
     
    Last edited: Feb 23, 2019
  3. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @AntonBaranov

    BTW having 5000-10000 GameObjects in scene sounds overkill no matter if you get the draw calls down by batching.

    Also, being able to interact with UI elements doesn't need one canvas per element, you can make a screen space Panel/Image clickable/interactable in similar manner to button.
     
  4. AntonBaranov

    AntonBaranov

    Joined:
    Mar 7, 2015
    Posts:
    11
    Mostly, I solved my problem just change component TextMeshProUGUI to TextMeshProText. It wasn't good decision use this component for Canvas in World Space mode.
     
  5. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    I would stick to one canvas and many panels and calculate size by reference worldspace points.