Search Unity

OnMouseDown does not work on a monitor while having a VR (XR) setup

Discussion in 'AR/VR (XR) Discussion' started by datagreed, Sep 4, 2020.

  1. datagreed

    datagreed

    Joined:
    Sep 17, 2018
    Posts:
    42
    I 've set up a project with an XR Rig using new XR Management.
    The second screen (PC monitor) renders a camera with a Culling Mask placed on the scene, so a person can spectate from some othe point than POV.
    I want the spectator to be able to click on the Game Objects. I use abasic script on these objects with colliders, that goes like this:

    Code (CSharp):
    1. public class ClickableObject: MonoBehaviour
    2.     {
    3.  
    4.         public void OnMouseDown()
    5.         {
    6.             Debug.Log("Pressed object", gameObject);
    7.         }
    8.     }
    When I run the project and click on the GameObject nothing happens.

    However, if I select the camera while the project is running and change occlusionCulling parameter (does not mater off or on) - objects start reacting to clicks. This trick helps ONLY if I manually change this parameter in play mode. If I set it beforehand it won't make any difference.

    I even tried to add a script that automatically ticks occlusion culling on and then off after a second after launching the play mode, but that does not help - only clicking in the inspector helps.

    Please advise.
     
  2. datagreed

    datagreed

    Joined:
    Sep 17, 2018
    Posts:
    42
    Changing priority of the camera from 0 to one somhow solved the issue. Could someone please explain me why did it work?