Search Unity

Resolved Reacting to what's in the XR Socket

Discussion in 'XR Interaction Toolkit and Input' started by Skippu, Feb 24, 2021.

  1. Skippu

    Skippu

    Joined:
    Dec 3, 2016
    Posts:
    5
    I am trying to create a puzzle where depending on what object you place on a pedestal the environment changes. I have all of the code working for moving the objects the only thing I can't get working is to find the object that is in the XR Socket Interactor.

    Does anyone know the code or a method to assign the object in the XR Socket to a GameObject so I can pass it to my scripts to process?
     
  2. chris-massie

    chris-massie

    Unity Technologies

    Joined:
    Jun 23, 2020
    Posts:
    231
    You can get the selectTarget property of Socket Interactor to see which Interactable object is currently grabbed by it.
     
    Lisasz likes this.
  3. Skippu

    Skippu

    Joined:
    Dec 3, 2016
    Posts:
    5
    Thank you for the advice. I've had a look into implementing the SelectTarget to get the current object but I can't use the returned value. Is there a way to convert the XRBaseInteractable value to a GameObject or a way to access the selected object to pull values from it?
     
  4. DejaMooGames

    DejaMooGames

    Joined:
    Apr 1, 2019
    Posts:
    108
    XRBaseInteractable is a monobehaviour. If you want access to its gameObject just use
    Code (CSharp):
    1. var selectedGameObject = mySocket.selectTarget.gameObject;
    This does assume that you have checked that selectTarget isn't null.
     
  5. Skippu

    Skippu

    Joined:
    Dec 3, 2016
    Posts:
    5
    I was struggling to find a way to convert types to GameObject and that works perfectly.
    Thank you very much for your help.