Search Unity

Resolved Removing missing collider out of GrabInteractable collider list

Discussion in 'XR Interaction Toolkit and Input' started by Reitax, Jan 10, 2021.

  1. Reitax

    Reitax

    Joined:
    Oct 20, 2020
    Posts:
    2
    Heyho XR friends!

    I'm currently working on a small cooking simulator.
    Obviously cutting ingredients plays a big role, so that's where most of my time goes into and where most of my issues originate from.

    As of now an ingredient (e.g. an eggplant) consists of multiple cut parts, which are children of a parent object, so it does look like a whole solid eggplant, but in actuality the parent just holds together all seperate pieces.
    Upon cutting, which is basically touching a cut piece's trigger with a knife, said cut piece gets detached.
    Works without any issues so far.
    But as soon as I attach a XRGrabInteractable to the parent game object (so I can carry around the whole eggplant), start cutting half of an eggplant and then try to grab the "solid" half, it throws a "MissingReferenceException", since it's looking for a collider, which is now detached or destroyed.

    Then I noticed the collider list shows "Missing(Collider)", whenever a piece gets detached or destroyed.

    Is it possible to null check colliders within that list on runtime and automatically delete them, if not found?
    Sorry, if there's an obvious solution I didnt see. I'm new to Unity & XR.

    But thanks in advance for your help guys!
    Cheers
     
  2. Reitax

    Reitax

    Joined:
    Oct 20, 2020
    Posts:
    2
    Actually found an easy solution:
    Instead of taking all of the children colliders, the parent game object got his own collider (is Trigger enabled) and dragged this one to the collider list.
    Definitely not the best solution, but a solid one in my case.

    I didn't know the list gets automatically filled with children colliders, if empty (should have hovered to see the tooltip).
    But with a collider already in the list before running the game, it doesn't check its children colliders and therefore doesn't cause an issue.

    Edit: I'll mark this thread as solved, but any other solutions are definitely welcome!