Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Which one is more performant for VR development - 3d gameobjects or Canvas 2d elements for UI?

Discussion in 'VR' started by Esfekia, Dec 3, 2023.

  1. Esfekia

    Esfekia

    Joined:
    Mar 28, 2022
    Posts:
    7
    Hello all,

    We are in the process of implementing some UI elements for our VR game that we are developing in Unity for the Meta Quest devices. We are trying to decide between using 3d gameobjects for things like health bars or other UI elements or if we should stick with canvas and use 2d sprites as UI objects.

    From our experimentation we see that there are certainly some aliasing issues when it comes to the 2d UI path. Asking the question to chatgpt/bard etc I received the answer that "UI elements on a canvas can be batched efficiently, reducing draw calls." which is something that I am not familiar with.

    My particular question is: In a game where there will be many non-static NPC objects in the scene with GUI elements such as health bars, status effects and other visual information, would you go with 3d gameobjects (such as https://syntystore.com/products/interface-apocalypse-hud) or with traditional 2d UI elements with Canvas?

    I would also be grateful for any pointers/optimization tricks or tutorials out there (such as https://unity.com/how-to/unity-ui-optimization-tips) that would help us learn more about optimizing UI design.

    Best,
    Sertac
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,884
    2D UI is just rendering quads with textures on them. So do what you find easier.
    I would personally go with UI if you need text, or quads if it is just visuals
     
  3. Esfekia

    Esfekia

    Joined:
    Mar 28, 2022
    Posts:
    7
    Thank you so much DevDunk, what we are trying to find out is the overhead / draw calls and performance impact of one choice over the other. Let us say I want to have a dynamic health bar which will instantly change if a unit is hit. The dynamic health bar is above the unit in world space, since this is a VR game.

    a) I could implement this feature by creating an object pool of 10 little boxes and use those boxes to represent 10 hp each, so if the unit is at 70hp 7 of them would be visible and 3 would be returned to the object pool. I could make these share the same material and batch them.

    b) I could also implement this feature by creating a canvas above the unit and place a slider whose value will be dynamically changed through script when a unit is hit.

    My question is, for the use case where I will have 30-40 of these units on the screen, which option would be more performant? Aesthetics/ease of implementation etc. are secondary concerns, my primary concern here is performance. I would be grateful for tips and pointers for how I can make option b) more performant through some settings in Unity, too.

    Best regards,
    Sertac
     
  4. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    774
    This talk from Unite 2017 is good. Not sure if any info is out of date

     
  5. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,884
    If it's just boxes I'd go for quads. If you use URP or HDRP it will batch them together if they have the same shader. This will reduce the CPU overhead of sliders and canvases
     
  6. Esfekia

    Esfekia

    Joined:
    Mar 28, 2022
    Posts:
    7
    Thank you very much for the responses. I will try the quad approach. flashframe, great video, still relevant today.
     
    DevDunk and flashframe like this.
  7. eudendeew

    eudendeew

    Joined:
    Feb 5, 2017
    Posts:
    18
    For Quest devices (and VIVE) also read about compositor layers (there's a UI sample in their framework), this grabs the resulting UI render and displays it directly to the screens, offering higher resolution for better text quality and clear images/videos.

    The main disadvantage is that there will be aliasing on the edges (like the system menus on Quest) but this is less visible on the Quest 3. Also alpha blending is not recommended but just try it and profile/check performances later.