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

Question UI or not UI

Discussion in '2D' started by pabloivme, Nov 17, 2022.

  1. pabloivme

    pabloivme

    Joined:
    Oct 23, 2016
    Posts:
    4
    Normally it's easy to differentiate the UI from the game, but in this kind of game, is the game done using the Canvas? I would think so because of the text and the grid layouts, but there are things like line renderer or the need of sorting layers or colliders that would make it strange to be UI.

    Thoughts?

     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,954
    Your choice really.

    Three (3) primary ways that Unity draws / stacks / sorts / layers / overlays stuff:

    https://forum.unity.com/threads/orthographic-camera-rendering-order.1114078/#post-7167037

    In short,

    1. The default 3D Renderers draw stuff according to Z depth - distance from camera.

    2. SpriteRenderers draw according to their Sorting Layer and Sorting Depth properties

    3. UI Canvas Renderers draw in linear transform sequence, like a stack of papers

    If you find that you need to mix and match items using these different ways of rendering, and have them appear in ways they are not initially designed for, you need to:

    - identify what you are using
    - search online for the combination of things you are doing and how to to achieve what you want.

    There may be more than one solution to try.

    Additional reading in the official docs:

    https://docs.unity3d.com/Manual/2DSorting.html

    And SortingGroups can also be extremely helpful in certain circumstances:

    https://docs.unity3d.com/Manual/class-SortingGroup.html

    There is alo this:

    https://github.com/JohannesDeml/unity-ui-extensions
     
  3. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,492
    Would say you'll certainly profit from the layouting system if you use UI. That way your game scales better with different screen ratios.
    It can usually be combined reasonably well with normal rendering and if all else fails, render normally onto a RenderTexture and add that one to the UI.
     
  4. pabloivme

    pabloivme

    Joined:
    Oct 23, 2016
    Posts:
    4
    @Kurt-Dekker I think using the 3d renderer strategy is a good idea, perhaps using one canvas for the UI as Screen Space - Camera, and another one for the actual game using World Space.

    Also we have the option of the child canvas component, that allows changing the sorting layer. Have you found any issues with this component? I once had an issue where the child canvas element was preventing clicks on the phone, not on the editor.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,954
    Making games has nothing BUT issues. You're using HUNDREDS of separate layers of software, all built by different people, and all those modules have dependencies on each other. It's ALL issues. Nothing but issues. That's why we get paid the Big Bucks(tm): to solve issues and make games.

    Go make games. When you have actual issues (as opposed to fantasy maybe-you-have issues), here is 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, especially any errors you see
    - links to documentation you used to cross-check your work (CRITICAL!!!)

    The documentation is critical because a) it shows that you're actually serious about your problem, not just shoveling it onto strangers on a forum, and b) the answer is likely in the documentation if you look properly.