The problem of UIPointer ray penetration on VRTK overlapping Canvas (Unity VR)

When there are overlapping WordSpace Canvas, UIPointer rays will penetrate Canvas, causing an error to be triggered.

Problem inquiry

The solution goes straight to the end“ resolvent ”Section.
2020 supplement: the problem has been solved, please move to this article: https://www.azimiao.com/7509.html

The test scenario is shown in the following figure. There are two overlapping Canvas, called Canvas3 and Canvas4, respectively. There is a button under each of them.

 Scene Level

A script is attached to Canvas as follows:

 void Start(){ if(this.GetComponentInChildren<Button>()){ this. GetComponentInChildren<Button>().onClick. AddListener(this.onBtnClick); } } void onBtnClick(){ Debug. Log("it's" + this.name); }

After running, the ray points to Canvas3, as if it penetrates Canvas3, and the printed information is Canvas4.

 Log information

The interaction between VR and UGUI must be carried out through the EventSystem, and the collision detection code was found through the VRTK_UIPointer script.

The code transmits the starting point and direction of the ray to EventSystem , via EventSystem. RaycastAll Get the UI pointed by the ray:

 //VRTK_VRInputModule.cs protected virtual List<RaycastResult> CheckRaycasts(VRTK_UIPointer pointer) {        RaycastResult raycastResult = new RaycastResult(); raycastResult.worldPosition = pointer. GetOriginPosition(); raycastResult.worldNormal = pointer. GetOriginForward(); pointer.pointerEventData.pointerCurrentRaycast = raycastResult; List<RaycastResult> raycasts = new List<RaycastResult>(); eventSystem. RaycastAll(pointer.pointerEventData, raycasts); return raycasts; }

In this case, print the collision results:

 Debug. Log ("I hit the UI!, a total of"+raycasts. Count); for (int i = 0; i < raycasts.Count; i++) { Debug. Log(raycasts[i].gameObject.name,raycasts[i].gameObject); }

 Operation results

It is found that the returned result is only two components under Canvas4 (the screenshot omits the drag component automatically created by VRTK).

about EventSystem. RaycastAll The official document just says: use all the set BaseRaycaster Conduct collision detection.

I searched the open source code of Unity, but didn't find it EventSystem. RaycastAll The specific implementation of. Later, I tried to modify the parameter attribute values and adjust the Layer, but it didn't work.

Summary: EventSystem. RaycastAll Instead of returning the All collision directly, (perhaps) spit out the objects it thinks are correct according to the internal sorting logic.

resolvent

  1. 20201216 Supplement: This problem has been solved. Please refer to the following articles:

VRTK solves the problem of multi Canvas ray penetration (WorldSpace)

  1. Probabilistic solution
    Attach these overlapping Canvas Graphic Raycaster Component Blocking Objects Change to All
     Graphic Raycaster This is a probabilistic solution to penetration. Some panels work, while others are not.
    When it is changed to All, it is also invalid. After running, close and open the rear panel, which can basically solve the problem. The reason is unknown, which may be related to the internal sorting logic.

  2. cut the weeds and dig up the roots
    Avoid overlapping Canvas at the same time in the design phase. If you have to appear, please pray for yourself.

  3. await one's doom
    Waiting for Unity to explain.

Zimiao haunting blog (azimiao. com) All rights reserved. Please note the link when reprinting: https://www.azimiao.com/4950.html
Welcome to the Zimiao haunting blog exchange group: three hundred and thirteen million seven hundred and thirty-two thousand

Comment

*

*

Comment area

  1. Cc 07-23 09:31 reply

    "VR must interact with UGUI through EventSystem"
    Thank you, the blogger 😳
    PS: How can you build a good blog

    • hare 07-23 21:19 reply

      I'm very glad to help you. This blog is built with one click of WordPress, the most popular blog program in the world.

  2. aby 11-28 17:29 reply

    Thank you for helping me!