How work property Ignore Reversed Graphics in Graphic Raycaster?

Hi, I want to understand how work property ** Ignore Reversed Graphics in Graphic Raycaster **.

_
What I know about Graphic Raycasters and test I have done:

Graphic Raycaster giving us ability to raycast UI elements.

If we have nested canvases they have own Graphic Raycast component who is controling only one canvas (parent-canvas Graphic Raycaster have no power over child-canvases ).

If I disable Graphic Raycaster in canvas I can’t for example click Button in that canvas.

_

Blocking objects property:_

Important: not kind of object but type of collider define how element block raycast.

I set CanvasGreen - property Render Mode: Screen Space - Camera - to see gameObject before UI elements.

I set Graphic Raycaster ( in CanvasRed) - property Blocking Objects: Tree D. Now 3D object like cube block raycasts. (have Mesh Collider - 3D collider)

If I set to Blocking Objects: Two D - elements 2D like sprites block raycasts. (I added Box Collider2D before)
_

How work checkBox Ignore Reversed Graphic?

I put diffrent elements over Button:

I used sprite (with BoxCollider2D) and reversed it- set scale to -1. No effect.

I used quad and reversed it - set scale to -1. No effect.

I used Image - in same canvas and in other - and reversed it. No effect.

Can someone give me example how its work?

I know theory and read documentation and scripting api for graphic raycaster. And I spend about 4 our on test and internet research, so I need example not theory.

Thank you for help :slight_smile:

When you said “a scale of -1”. Do you mean on one axis or on two? If you scale an object on two axis it would face in the right direction. Only if you scale it on one axis (x or y) then it would be reversed.

However i barely used the new UI system. I just know that the graphics raycaster doesn’t use the physics(2d / 3d) raycast but holds a list of all active graphics in a canvas and simply does a the hit check manually in 2d. Basically a “point inside area check”. I haven’t looked at how it actually handles blocking geometry. However i think the “Ignore Reversed Graphic” option just applies to Graphics and not colliders.

edit

As i though the Graphics raycaster does simply use this code before the actual “raycast” against the UI elements:

if (canvas.renderMode != RenderMode.ScreenSpaceOverlay && blockingObjects != BlockingObjects.None)
{
    float dist = 100.0f;

    if (eventCamera != null)
        dist = eventCamera.farClipPlane - eventCamera.nearClipPlane;

    if (blockingObjects == BlockingObjects.ThreeD || blockingObjects == BlockingObjects.All)
    {
        RaycastHit hit;
        if (Physics.Raycast(ray, out hit, dist, m_BlockingMask))
        {
            hitDistance = hit.distance;
        }
    }

    if (blockingObjects == BlockingObjects.TwoD || blockingObjects == BlockingObjects.All)
    {
        RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, dist, m_BlockingMask);

        if (hit.collider != null)
        {
            hitDistance = hit.fraction * dist;
        }
    }
}

“hitDistance” is simply the reference “depth”. It’s initialized with a huge number float hitDistance = float.MaxValue; so when blockingObjects is None the test later will always pass.

So as you can see “ignoreReversedGraphics” is not used at all for the blocking object, only for the actual Graphic objects. It’s used like this:

if (ignoreReversedGraphics)
{
    if (eventCamera == null)
    {
        // If we dont have a camera we know that we should always be facing forward
        var dir = go.transform.rotation * Vector3.forward;
        appendGraphic = Vector3.Dot(Vector3.forward, dir) > 0;
    }
    else
    {
        // If we have a camera compare the direction against the cameras forward.
        var cameraFoward = eventCamera.transform.rotation * Vector3.forward;
        var dir = go.transform.rotation * Vector3.forward;
        appendGraphic = Vector3.Dot(cameraFoward, dir) > 0;
    }
}

So it doesn’t even care about the scale but only about rotation which seems a bit strange.

edit2
I always forget that the UI source code is open source on bitbucket ^^. I replaced code samples ^^. The first one was taken from here, the second was taken from here (just a few lines down).