cancel
Showing results for 
Search instead for 
Did you mean: 

Detecting laser pointer hovering on button (Oculus Quest - Unity3D)

vrz_dev
Protege

Stack:

  • Unity 2019.3

  • Oculus VR Integration

  • macOS Catilina

I have a Unity scene with a VR interface composed by a Canvas (World Space coordinates) and two buttons. The canvas has attached an OVR Raycaster objects which uses a laser pointer. Overall it works well, but when I try to intercept the event produced by hovering the laser pointer on the button, I can get only the click event.

I'm using the following script (attached to the button):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class VRButton : MonoBehaviour, IPointerEnterHandler, IPointerClickHandler, ISelectHandler
{
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

}

public void OnPointerEnter(PointerEventData eventData)
{
Debug.Log("Enter!");
transform.localScale *= 1.2f;
}

public void OnPointerExit(PointerEventData eventData)
{
Debug.Log("Exit!");
transform.localScale /= 1.2f;
}

public void OnPointerClick(PointerEventData eventData)
{
Debug.Log("Clicked!");
}
}

The strange thing is that both OnPointerEnter and OnPointerClick get called when I point the button with the laser and click. Just hovering the doesn't trigger any event (nor OnPointerExit or OnPointerEnter).

This is my ADB log:

03-15 22:59:53.085 13339 13355 I Unity : Clicked!

03-15 22:59:53.085 13339 13355 I Unity : UnityEngine.Logger:Log(LogType, Object)

03-15 22:59:53.085 13339 13355 I Unity : UnityEngine.EventSystems.EventFunction`1:Invoke(T1, BaseEventData)

03-15 22:59:53.085 13339 13355 I Unity : UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)

03-15 22:59:53.085 13339 13355 I Unity : UnityEngine.EventSystems.OVRInputModule:ProcessMousePress(MouseButtonEventData)

03-15 22:59:53.085 13339 13355 I Unity : UnityEngine.EventSystems.OVRInputModule:ProcessMouseEvent(MouseState)

03-15 22:59:53.085 13339 13355 I Unity :

03-15 22:59:53.085 13339 13355 I Unity : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)

03-15 22:59:53.085 13339 13355 I Unity :

03-15 22:59:53.085 13339 13355 I Unity : Enter!

03-15 22:59:53.085 13339 13355 I Unity : UnityEngine.Logger:Log(LogType, Object)

03-15 22:59:53.085 13339 13355 I Unity : VRButton:OnPointerEnter(PointerEventData)

03-15 22:59:53.085 13339 13355 I Unity : UnityEngine.EventSystems.EventFunction`1:Invoke(T1, BaseEventData)

03-15 22:59:53.085 13339 13355 I Unity : UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)

03-15 22:59:53.085 13339 13355 I Unity : UnityEngine.EventSystems.BaseInputModule:HandlePointerExitAndEnter(PointerEventData, GameObject)

03-15 22:59:53.085 13339 13355 I Unity : UnityEngine.EventSystems.OVRInputModule:ProcessMousePress(MouseButtonEventData)

03-15 22:59:53.085 13339 13355 I Unity : UnityEngine.EventSystems.OVRInputModule:ProcessMouseEvent(MouseState)

How can I fix it?

2 REPLIES 2

O.KENTO
Protege

I had the same problem and solved it.
I wrote an article in Japanese, so please translate it.
https://qiita.com/OKsaiyowa/items/913885195095afd06358

Thank you man, your solution saved me a lot of time. Works like a charm!