Search Unity

Feedback Make RaycastComparer virtual in EventSystem or respect TransparencySortMode by default

Discussion in 'Input System' started by VoodooDetective, Jan 6, 2021.

  1. VoodooDetective

    VoodooDetective

    Joined:
    Oct 11, 2019
    Posts:
    239
    Right now in my 2.5D game, I'm having to jump through hoops to get the EventSystem to respect the render order based on TransparencySortMode. It'd be nice if that worked by default in the EventSystem RaycastComparer.

    Right now my only two options are to make all objects' z-axis position mirror their y-axis position OR this:

    Code (CSharp):
    1.             // Set Raycast Comparer with Black Magic
    2.             typeof(EventSystem)
    3.                 .GetField("s_RaycastComparer", BindingFlags.Static | BindingFlags.NonPublic)
    4.                 .SetValue(eventSystem, (Comparison<RaycastResult>)CustomRaycastComparer);
    Where my CustomRaycastComparer does this:


    Code (CSharp):
    1.  
    2. ...
    3.             if (lhs.sortingLayer != rhs.sortingLayer)
    4.             {
    5.                 // Uses the layer value to properly compare the relative order of the layers.
    6.                 var rid = SortingLayer.GetLayerValueFromID(rhs.sortingLayer);
    7.                 var lid = SortingLayer.GetLayerValueFromID(lhs.sortingLayer);
    8.                 return rid.CompareTo(lid);
    9.             }
    10.             else if (lhs.gameObject.layer != UILayer && rhs.gameObject.layer != UILayer)
    11.             {
    12.                 // Sorting Layers Match
    13.                 return lhs.gameObject.transform.position.y.CompareTo(rhs.gameObject.transform.position.y);
    14.             }
    15. ...
    16.  
     
    Last edited: Jan 6, 2021
  2. VoodooDetective

    VoodooDetective

    Joined:
    Oct 11, 2019
    Posts:
    239
    Actually, it'd be perfect if s_RaycastComparer was public. How do I request that?
     
  3. VoodooDetective

    VoodooDetective

    Joined:
    Oct 11, 2019
    Posts:
    239
    Just wanted to bump this
     
  4. VoodooDetective

    VoodooDetective

    Joined:
    Oct 11, 2019
    Posts:
    239
    UNITY!!!!!!!!!!!!