Search Unity

Question Occluding GameObjects in a specific layer, but being transparent to others

Discussion in 'Editor & General Support' started by test_josef, Dec 9, 2022.

  1. test_josef

    test_josef

    Joined:
    Jun 10, 2022
    Posts:
    1
    Hi there!
    I have had a lot of trouble with some occlusion/culling problems lately, and I didnt find any good answers online, so I am finally asking this forum for help.

    I am developing an AR-app (but I think this problem is not AR specific), and have problems with text placement and occlusion. What I need:
    A text object (TextMeshPro, with a plane Gameobject as child to create a cheap "background") should be able to cover up/occlude ALL other text objects behind it. So if several text fields are overlapping, only the first on will be visible, and only parts of the others.

    BUT (now it gets weird..), I need all other GameObejcts (and in the AR case, the background) to still be visible!

    I tried a lot of stuff with Renderes and culling Masks, but I am not very experienced with these and couldnt produce the desired effect.

    If anyone can help me with this problem, it will be very much appreciated!

    Thanks!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,686
    Sounds like perhaps you are mixing and matching the ways Unity sorts stuff?

    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