Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Object grabbed event?

Discussion in 'AR/VR (XR) Discussion' started by Verdemis, Apr 21, 2020.

  1. Verdemis

    Verdemis

    Joined:
    Apr 27, 2013
    Posts:
    92
    Hi everyone,

    I'm making my first steps with VR and I'm working on a small sandbox to get familiar how everything works. At the moment I'm trying to figure out if there is a way to know when a object has been grabbed? I'm working with the Unity XR Interaction Toolkit. It tried to use the OnSelectEnter Event on my XR Grab Interactable Object, but it looks like this event get's triggerd at the second the player tabs the grab button. But I need some kind of notification when the object has reached the players hand.

    Has anyone a hint for me?

    Thx for your help!
     
  2. dan3s2020

    dan3s2020

    Joined:
    Dec 27, 2019
    Posts:
    2
    i have a script that hides the hands when i grab something,i think you can use these onEnable/onDisable do to other actions too

    using UnityEngine;
    using UnityEngine.XR.Interaction.Toolkit;
    public class HandHider : MonoBehaviour
    {
    public GameObject handObject = null;
    private HandPhysics handPhysics = null;
    private XRDirectInteractor interactor = null;
    private void Awake()
    {
    handPhysics = handObject.GetComponent<HandPhysics>();
    interactor = GetComponent<XRDirectInteractor>();
    }
    private void OnEnable()
    {
    interactor.onSelectEnter.AddListener(Hide);
    interactor.onSelectExit.AddListener(Show);
    }
    private void OnDisable()
    {
    interactor.onSelectEnter.RemoveListener(Hide);
    interactor.onSelectExit.RemoveListener(Show);
    }
    private void Show(XRBaseInteractable interactable)
    {
    handPhysics.TeleportToTarget();
    handObject.SetActive(true);
    }
    private void Hide(XRBaseInteractable interactable)
    {
    handObject.SetActive(false);
    }
    }
     
    StefanCar23 likes this.