Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question ¿BUG? RaycastAll fails with URP + (OpenXR OR SteamVR)

Discussion in 'UGUI & TextMesh Pro' started by miguelmv, Nov 25, 2021.

  1. miguelmv


    Jan 24, 2018
    This is a copy of a post that I writed in the URP sub-forum (without response) but touch three features. Im almost sure that this is a bug, but ... ¿If I asign the BUG tag will get more attention? ¿Could a developer check this?

    In short, I get response from the RaycastAll() method against a vanilla project with a vanilla canvas (in world space) with a button, in these situations:
    • Project with URP
    • Project with SteamVR
    • Project with OpenXR

    But, in these cases the SAME code responds nothing, with no errors, no warnings:
    • Working project with URP then added SteamVR
    • Working project with URP then added OpenXR
    • Working project with SteamVR then added URP
    • Working project with OpenXR then added URP

    The goal is an eye raycaster that does not need colliders (whit physics raycasts) attached to the UI "selectable" elements. And the script works fine when there is no URP plus an XR plugin, even the extended code that choose the selectable and send it the events OnPointerEnter, OnPointerExit, etc.

    The minimal test code when use OpenXR or SteamVR (the diference wiht URP is only that the center of the view is taken from Screen.width, etc. By the way, I dont know why XRSettings.eyeTextureXX is zero in the Start() handler and I put it in Update() ) is this:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.EventSystems;
    3. using System.Collections.Generic;
    4. using UnityEngine.XR;                    // XRSettings
    6. public class RaycasterMiradaTest : MonoBehaviour
    7. {
    8.     private Vector2                 centro;
    9.     private EventSystem             m_eventSystem;
    10.     private PointerEventData        m_pointerEvent;
    12.     //------------------------------------------------------------------
    13.     private void Start()
    14.     {
    15.         m_eventSystem     = EventSystem.current;
    16.         m_pointerEvent     = new PointerEventData(m_eventSystem);
    17.     }
    19.     //------------------------------------------------------------------
    20.     private void Update()
    21.     {
    22.         // Con RV                                             // No VR
    23.         centro.x = XRSettings.eyeTextureWidth / 2;         // Screen.width / 2;
    24.         centro.y = XRSettings.eyeTextureHeight / 2;         // Screen.height / 2;
    25.         m_pointerEvent.position = centro;
    27.         List<RaycastResult> resultadosRayo = new List<RaycastResult>();
    28.         m_eventSystem.RaycastAll(m_pointerEvent, resultadosRayo);
    30.         Debug.Log("Num objs: " + resultadosRayo.Count);  
    31.     }
    32. }
    And this is the full hierarchy, and the output in the (minimal and fine working) OpenXR project:

    If then I add (and configure) URP, voila, response is gone.

    ¿A bug?

    Any other simple solution for an eye raycaster without colliders in a canvas worldspace will be valid for me.