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 Quick Outline asset — how to ensure outline is at correct "depth"?

Discussion in 'Scripting' started by josephmalam, Nov 18, 2022.

  1. josephmalam

    josephmalam

    Joined:
    Nov 4, 2022
    Posts:
    6
    I'm using the Quick Outline asset — https://assetstore.unity.com/packages/tools/particles-effects/quick-outline-115488

    I want to use it to highlight objects the player can interact with when they are inside a collider object, like here:

    My issue is that the outline does not seem to be at the right z-index depth — as you see in the bottom right corner of the object, the player's hair is "under" the outline.

    My code is:

    Code (CSharp):
    1. private void OnTriggerEnter(Collider other)
    2.     {
    3.         if (other.name == "Player")
    4.         {
    5.             var outline = gameObject.AddComponent<Outline>();
    6.             outline.OutlineMode = Outline.Mode.OutlineAll;
    7.             outline.OutlineColor = Color.yellow;
    8.             outline.OutlineWidth = 3f;
    9.         }
    10.     }
    Is there any way to prevent this?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,954
    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
     
  3. unity_5E58CB84874203FB3621

    unity_5E58CB84874203FB3621

    Joined:
    Dec 19, 2021
    Posts:
    1
    Hey Joseph! Have you solved it?