Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question How to add child colliders to a parent XRGrabInteractable collider list?

Discussion in 'XR Interaction Toolkit and Input' started by RThurbs, Aug 16, 2022.

  1. RThurbs

    RThurbs

    Joined:
    Jul 13, 2022
    Posts:
    12
    I have a GameObject which is a Grab Interactable, one of the children of that object has a box collider that I would like to add to the colliders list. However, when this collider is added to the XRGrabInteractable collider list, you are still unable to grab using the area defined by that box collider.

    The specific application is that the child can be shifted and rotated via user input, but I still want to be able to grab the parent element using the collider attached to the child.
     
  2. DanMillerU3D

    DanMillerU3D

    Unity Technologies

    Joined:
    May 12, 2017
    Posts:
    27
    As long as the collider is properly registered and follows the collision action matrix that should work. If you are modifying the colliders at runtime they might not be properly registered with the interactable component.

    If you have post some images of your object setup I might be able to provide some more details or help in how to set it up.
     
  3. RThurbs

    RThurbs

    Joined:
    Jul 13, 2022
    Posts:
    12
    Here is the object tree in question:

    Collider1.PNG

    The goal is to be able to grab and move FocusVR Standard Mount (1) using the box collider on Model.

    The mount has two box colliders itself, and the third box collider for the grab interactable should come from it's child, Model.

    Collider5.PNG
    Collider4.PNG

    We have not been able to get this setup to work in order to grab the element my the model hitbox. Currently we have a workaround where a third box collider on the top level imitates the center and size of the child hitbox, but this fails to capture rotation.

    Collider2.PNG
    Collider3.PNG
     
  4. RThurbs

    RThurbs

    Joined:
    Jul 13, 2022
    Posts:
    12
    Bumping this, still haven't got an answer
     
  5. DonJorris

    DonJorris

    Joined:
    Mar 29, 2016
    Posts:
    8
    I also stumbled upon this, so in case some else needs the solution: You simply have to unregister and reregister the interactable on the interaction manager like this:


    Code (CSharp):
    1.        
    2.         var coll = meshObj.AddComponent<SphereCollider>();
    3.         var inter = GetComponent<XRGrabInteractable>();
    4.         inter.colliders.Add(coll);
    5.         inter.interactionManager.UnregisterInteractable(inter.GetComponent<IXRInteractable>());
    6.         inter.interactionManager.RegisterInteractable(inter.GetComponent<IXRInteractable>());
    7.  
     
  6. Max-VRAM

    Max-VRAM

    Joined:
    Jan 11, 2022
    Posts:
    3
    @DonJorris - thanks for the answer. I spent hours trying to debug this.

    Calling unregister/registering on interactable directly after adding the collider didn't work for me, but spacing the calls out in a coroutine seemed to do the trick:

    Code (CSharp):
    1.     ...
    2.     inter.colliders.Add(coll);
    3.     StartCoroutine(ReregisterInteractable());
    4. }
    5.  
    6. private IEnumerator ReregisterInteractable()
    7. {
    8.     yield return new WaitForEndOfFrame();
    9.     inter.interactionManager.UnregisterInteractable(inter as IXRInteractable);
    10.  
    11.     yield return new WaitForEndOfFrame();
    12.     inter.interactionManager.RegisterInteractable(inter as IXRInteractable);
    13.  
    14.     yield return null;
    15. }
     
    alex_raum likes this.
  7. alex_raum

    alex_raum

    Joined:
    May 23, 2023
    Posts:
    1
    Oh Gosh, thank you so much, this drove me nuts!