Search Unity

Question XRGrabInteractable stops working after GameObject is detached from grab and transformed

Discussion in 'XR Interaction Toolkit and Input' started by KimberleyC, Sep 4, 2021.

  1. KimberleyC

    KimberleyC

    Joined:
    Mar 22, 2021
    Posts:
    20
    I'm currently trying to create a snap zone without using the XRSocketInteractor script. All works well--when the GameObject triggers the snap zone and is detached from the controller, it snaps right into place.
    However, the problem is that after it snaps into place, there's only a 1-2 second window where it can be grabbed back, but after that XRGrabInteractable doesn't seem to work anymore.

    upload_2021-9-4_22-33-16.png (the ray should be blue when encountering a grabbable GO)
    upload_2021-9-4_22-31-59.png (the 'snap zone')
    upload_2021-9-4_22-35-5.png (the GO becomes ungrababble a few seconds after being detached from the controller)

    This is the code I used to snap the GOs into place
    Code (CSharp):
    1. collision.gameObject.transform.parent.transform.rotation = transform.rotation;
    2. collision.gameObject.transform.parent.transform.position = transform.position;
    3.  
    4. if (collision.gameObject.GetComponentInParent<Entity>().xrGrab.isSelected)
    5.     targ.GetComponent<Renderer>().enabled = true;
    6. else
    7.     targ.GetComponent<Renderer>().enabled = false;
    and it's executed in the OnTriggerEnter and OnTriggerStay methods in the snap zone's script.

    Am I'm doing something wrong or is this is a bug?
     
  2. slippyfrog

    slippyfrog

    Joined:
    Jan 18, 2016
    Posts:
    42
    I'm working on something similar as the standard XRScoketInteractor isn't doing what I need it to. So far everything seems fine and I am not observing the issue you mentioned.

    It is hard to tell without more code, but how are you detaching the Interactable that is being snapped? Are you triggering the release action on the controller that releases the grabbed object or are your programmatically forcing the release of the object when the snap occurs (by setting the layer to 0)? If it is the latter, then perhaps you are not resetting state of something following the forced release of the object (ie layer id or something)?

    Do you have a large snippet of code?
    If it helps, I'm happy to share my code once its finished.
     
  3. KimberleyC

    KimberleyC

    Joined:
    Mar 22, 2021
    Posts:
    20
    Hi, sorry for the late reply. I've updated my code so that it sets the GO's isKinematic to true OnTriggerEnter and then back to false OnTriggerExit; this way, I've managed to grab back the GO from the snap zone, but the thing is that even though isKinematic is no longer true (I've checked by Debug.Log), it still behaves as such and does not respond to physics anymore. I'm not sure what I'm doing wrong here either hahaha.