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

Question How to hover / select a child object of a complex 3d-model

Discussion in 'XR Interaction Toolkit and Input' started by DevTom81, Oct 12, 2023.

  1. DevTom81

    DevTom81

    Joined:
    Aug 10, 2021
    Posts:
    8
    Hi,
    i am new in XRI Toolkit development.

    My problem is, that i can't find a way to hover / select only the touched part of a complex 3d-model (consisting of a hierarchy of objects).

    Every time i hovers / selects the hole object (root node of object). Every node has a
    XRGrabInteractable component, a mesh, a collider and a rigidbody.

    Please help!
     
  2. VRDave_Unity

    VRDave_Unity

    Unity Technologies

    Joined:
    Nov 19, 2021
    Posts:
    257
    Hey @DevTom81,

    The easiest way to address this is to make sure you manually define your Collider list in the parent and child nodes. By default, the XR Grab Interactable will search all child objects and auto-populate the collider list for any colliders it has found, even if they share a Game Object with another XR Grab Interactable (something we will probably add support for in the future). You will also want to check any child nodes that have their own children to ensure you aren't accidentally picking up colliders in an unwanted way. I have added some screenshots of the setup.
    upload_2023-10-12_11-47-38.png
    upload_2023-10-12_11-48-36.png

    One final note. If you are applying rigid body physics, you'll want to make sure the child objects are set to Is Kinematic or they will fly all over the place. Also, maintaining a scale of (1, 1, 1) will product spatial correct results if you move child objects around and then manipulate the parent. In my example, setting it to 0.5 causing some positional orbiting and shearing that would be unwanted in a shipping project.
     
  3. DevTom81

    DevTom81

    Joined:
    Aug 10, 2021
    Posts:
    8
    Hi @VRDave_Unity, thank you for your answer!
    Is there anything else to do? Does it work without unregistering from XRInteractionManager?
     
  4. VRDave_Unity

    VRDave_Unity

    Unity Technologies

    Joined:
    Nov 19, 2021
    Posts:
    257
    Hey @DevTom81,
    None of the child objects should be unregistered from the Interaction Manager, they just need their collider list manually. I guess I'm still a bit confused as to the full use case though. Are you trying to individually manipulate the child objects? And if so and you pull it away from the parent, do you want it to remain a separate entity or still be a part of the parent node?
     
  5. DevTom81

    DevTom81

    Joined:
    Aug 10, 2021
    Posts:
    8
    Hi @VRDave_Unity,
    thank you for your answer!

    > None of the child objects should be unregistered from the Interaction Manager, they just need their collider list manually.

    If I just manipulate each node's collider lists (each node only contains its own collider), it doesn't work. But if I unregister the interactables from XRInteractionManager, change the list of colliders and register again, it works and I can "grab" each individual node without moving the root object.

    Code (CSharp):
    1. var interactionManager = interactable.interactionManager;
    2.               var objectCollider = interactable.gameObject.GetComponent<Collider>();
    3.               InteractionManager.UnregisterInteractable(interactable);
    4.               interactable.colliders.RemoveAll(x => x != currentCollider);
    5.               interactionManager.RegisterInteractable(interactable);
    But I'm afraid that's not the right way. Is there a way to do it without unregistration/ registration?

    > I guess I'm still a bit confused as to the full use case though. Are you trying to individually manipulate the child objects? And if so and you pull it away from the parent, do you want it to remain a separate entity or still be a part of the parent node?

    Yes, my goal is to decompose complex objects.