Search Unity

Discussion Alternatives for displaying world space UI on top of objects

Discussion in 'Editor & General Support' started by Ts1nd, Jun 12, 2023.

  1. Ts1nd

    Ts1nd

    Joined:
    Jan 24, 2021
    Posts:
    108
    I have been using camera stacking to get it done where the second camera overlay would display only UI. However I found out that using ANY kind of stacking (or separate camera for that matter) reduces the fps by around 30% even if the culling layers are completely off! It looks like big oversight from Unity side.
    So I need a new workaround that uses only 1 camera but still allows hiding objects behind world space UIs such as healthbars. Any tips?
     
  2. Ts1nd

    Ts1nd

    Joined:
    Jan 24, 2021
    Posts:
    108
    Why is this forum so dead?
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    The first tip is how to post in a way that people can easily respond.

    This is 100% on you, not us.

    How to report your problem productively in the Unity3D forums:

    http://plbm.com/?p=220

    This is the bare minimum of information to report:

    - what you want
    - what you tried
    - what you expected to happen
    - what actually happened, log output, variable values, and especially any errors you see
    - links to documentation you used to cross-check your work (CRITICAL!!!)

    The last one is especially important because it shows us that you're actually lifting a finger here.

    Otherwise you're just typing. It's up to YOU to catch our attention well.

    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/

    It actually sounds a lot more like you've never profiled your game.

    DO NOT OPTIMIZE "JUST BECAUSE..." If you don't have a problem, DO NOT OPTIMIZE!

    If you DO have a problem, there is only ONE way to find out. Always start by using the profiler:

    Window -> Analysis -> Profiler

    Failure to use the profiler first means you're just guessing, making a mess of your code for no good reason.

    Not only that but performance on platform A will likely be completely different than platform B. Test on the platform(s) that you care about, and test to the extent that it is worth your effort, and no more.

    https://forum.unity.com/threads/is-...ng-square-roots-in-2021.1111063/#post-7148770

    Remember that optimized code is ALWAYS harder to work with and more brittle, making subsequent feature development difficult or impossible, or incurring massive technical debt on future development.

    Notes on optimizing UnityEngine.UI setups:

    https://forum.unity.com/threads/how...form-data-into-an-array.1134520/#post-7289413

    At a minimum you want to clearly understand what performance issues you are having:

    - running too slowly?
    - loading too slowly?
    - using too much runtime memory?
    - final bundle too large?
    - too much network traffic?
    - something else?

    If you are unable to engage the profiler, then your next solution is gross guessing changes, such as "reimport all textures as 32x32 tiny textures" or "replace some complex 3D objects with cubes/capsules" to try and figure out what is bogging you down.

    Each experiment you do may give you intel about what is causing the performance issue that you identified. More importantly let you eliminate candidates for optimization. For instance if you swap out your biggest textures with 32x32 stamps and you STILL have a problem, you may be able to eliminate textures as an issue and move onto something else.

    This sort of speculative optimization assumes you're properly using source control so it takes one click to revert to the way your project was before if there is no improvement, while carefully making notes about what you have tried and more importantly what results it has had.
     
  4. Ts1nd

    Ts1nd

    Joined:
    Jan 24, 2021
    Posts:
    108
    The question was extremely simple. I never asked about optimization or profiling. Maybe try reading the actual question next time before copy pasting post? Tip: it's in the title.
     
  5. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,074
    How many milliseconds are added to your rendering when you add secondary camera.
    Also, what rendering pipeline you are using.
     
    Kurt-Dekker likes this.
  6. Ts1nd

    Ts1nd

    Joined:
    Jan 24, 2021
    Posts:
    108
    Rendering has unnoticable increase as the camera is not rendering anything. The biggest jump is in script section in Inl_RenderCameraStack around 3ms jump with the rendering disabled on the second camera. That's on PC. On mobile (my target platform) the jump is much higher. I am using URP. I like the fps without second camera and this is where I would like to focus my implementation. Any ideas how to achieve it without camera stacking?
     
  7. Ts1nd

    Ts1nd

    Joined:
    Jan 24, 2021
    Posts:
    108
    Anyone knows any other way to display UI on top of objects?
     
  8. Ruslank100

    Ruslank100

    Joined:
    Apr 11, 2018
    Posts:
    46
    If you simply want to show some UI on top of 3D objects, with a screen space canvas (so you need just one camera and one canvas), you can convert position of 3D objects to screen space position for UI elements you want to show above them, using reference_to_camera.WorldToScreenPoint(position). You can add some arbitrary offset to both world and screen position in order to keep the UI above the objects no matter how far or close the object is