Search Unity

XR Socket Interactor unsocket GameObject

Discussion in 'Scripting' started by Loki18000, Oct 28, 2020.

  1. Loki18000

    Loki18000

    Joined:
    Apr 1, 2015
    Posts:
    75
    Hello!
    I'm not sure if anyone can help with this but I need to unsocket a GameObject from the XR Socket Interactor after the GameObject has been destroyed.

    I can get a ref to the GameObject using
    Code (CSharp):
    1. GetComponent<XRSocketInteractor>().selectTarget.gameObject
    But this is read only so how would I set it to null so the socket can be used again.

    Since its read only using
    Code (CSharp):
    1. GetComponent<XRSocketInteractor>().selectTarget.gameObject = null
    won't work.

    Thank you for any help.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,749
    What API causes it to be "socketed?"

    Did you look in there to see if there is an equivalent "unsocket" command?
     
  3. Loki18000

    Loki18000

    Joined:
    Apr 1, 2015
    Posts:
    75
    I did but I couldn't see anything yet. I'm going to continue to look through it. I'm still pretty new to the XR toolkit.
     
  4. Loki18000

    Loki18000

    Joined:
    Apr 1, 2015
    Posts:
    75
    I used simple box collider with a OnTriggerEnter to achieve the same effect. As far as I know it works as intended.
     
    Kurt-Dekker likes this.
  5. betziv

    betziv

    Joined:
    Feb 27, 2021
    Posts:
    1
    Can you please give more details on how exactly have you used that method? Can't figure out your solution.
     
  6. BJump

    BJump

    Joined:
    Apr 30, 2023
    Posts:
    12
    I realize this is an old thread but it popped up many times while I was trying to figure out the same thing, so I am going to provide the answer I figured out. Basically you have to tell the interaction manager to eject (or rather exit) the selected item.

    yourSocket.interactionManager.SelectExit(yourSocket, itemSocketed)


    the only issue is that the item will automatically and instantly pop back into the socket since its still in range, this specific instance might not need anything extra as he stated the item was destroyed so no longer exists in order to get pulled into the socket. the solution i had to stop the auto resocket was to

    selectEntered(){ yourSocket.GetComponent<SphereCollider>().enabled = false;}


    then in your method where the release of the socket happens you

    Code (CSharp):
    1.  
    2. void yourMethod()
    3. {
    4.      //your code releasing the socket
    5.      StartCoroutine("activateSocket");
    6. }
    7.  
    8. IEnumerate activateSocket()
    9. {
    10.      yield return new WaitForSeconds(.5f); // gives the object time to clear the sphere collider attachment point
    11.      yourSocket.GetComponent<SphereCollider>().enabled = true; //activates it so its ready for the next item
    12. }
    13.  

    hope this helps anyone else that's still running across this, I hate to be the one to necro thread but I found this post 6 times while looking for my answers