Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question How to get attached Interactable from Interactor

Discussion in 'XR Interaction Toolkit and Input' started by unity_ZHAStN3iS0v5PA, May 5, 2023.

  1. unity_ZHAStN3iS0v5PA

    unity_ZHAStN3iS0v5PA

    Joined:
    Jan 23, 2020
    Posts:
    6
    I would like to gain access to whatever the grabbed game object is. I need a component on the Interactor Object to gain a reference from the interactable. I am not sure how I would be able to access it as it doesn't seem like interactors are able to. Any ideas?
     
  2. mikeNspired

    mikeNspired

    Joined:
    Jan 13, 2016
    Posts:
    80
    Code (CSharp):
    1. [SerializeField] private XRDirectInteractor _xrDirectInteractor;
    2.  
    3.     private void Start()
    4.     {
    5.         _xrDirectInteractor.selectEntered.AddListener(SelectEnter);
    6.     }
    7.  
    8.     private void SelectEnter(SelectEnterEventArgs x)
    9.     {
    10.         Transform grabbedObject = x.interactorObject.transform;
    11.     }
     
  3. feathered_wing

    feathered_wing

    Joined:
    Dec 5, 2020
    Posts:
    20
    Hope that helps, if you don't understand, please reply me and I will explain more for you.

    Code (CSharp):
    1.  
    2. XRBaseInteractor interactor = (member as XRBaseInteractor);
    3. if (interactor.interactablesSelected != null && interactor.interactablesSelected.Count>0)
    4. {
    5.       if (interactor.interactablesSelected[0].transform.gameObject.name.Contains("¥"))
    6.       {
    7.            interactor.interactablesSelected[0] balabalbala
    8.            //add your code.interactor.interactablesSelected[0] is your first select interactable
    9.       }
    10. }