cancel
Showing results for 
Search instead for 
Did you mean: 

OnPointerExit & OnPointerEnter events unexpectedly fire after pressing & releasing the trigger

VTDA
Explorer
  • I have a simple script that plays an audio clip when the OnPointerEnter event fires and stops when the OnPointerExit event is fired
  • If I hover over and then off of a UI element, like a toggle or button, the audio plays / stops as expected
  • If I pull the controller trigger while hovering over UI and release, the OnPointerExit & OnPointerEnter events fire, even though I never moved the pointer from the UI
  • This only occurs when in VR, not in a desktop scene, and is feels like a bug

Unity 2022.3.20f1
Meta SDK v62

1 REPLY 1

VTDA
Explorer

This is what I did in lieu of an official fix by Meta to satisfy my specific use case (to predictably play audio on hover events):

using UnityEngine;
using Oculus.Interaction;

public class PlayAudioOnHoverMETA : MonoBehaviour
{
    [SerializeField] private AudioSource audioSource;
    private bool isPointerOver = false;
    
    void Start()
    {
        PointableCanvasModule.WhenSelectableHovered += OnSelectableHovered;
        PointableCanvasModule.WhenSelectableUnhovered += OnSelectableUnhovered;
    }

    void OnDestroy()
    {
        PointableCanvasModule.WhenSelectableHovered -= OnSelectableHovered;
        PointableCanvasModule.WhenSelectableUnhovered -= OnSelectableUnhovered;
    }

    private void OnSelectableHovered(PointableCanvasEventArgs args)
    {
        if (args.Hovered == this.gameObject && audioSource != null && !audioSource.isPlaying && !isPointerOver)
        {
            audioSource.Play();
            isPointerOver = true;
            //Debug.Log("Play Audio Clip on Enter\n");
        }
    }

    private void OnSelectableUnhovered(PointableCanvasEventArgs args)
    {
        if (audioSource != null)
        {
            audioSource.Stop();
            isPointerOver = false;
            //Debug.Log("Stop Audio Clip on Exit\n");
        }
    }
}