I cant work out how to get the player to drop the XRGrabInteractable item by code (when they die in game). I’ve seen a few threads saying to disable the XRGrabInteractable or disable enableInteractions on the XRBaseInteraction, but the player can still hold onto the item throughout the death sequence. I’ve tried disabling and reenabling the associated colliders as well.
At the moment, I have a code which disables the enableInteractions part of the XRBaseInteractions script, but the player can still hold onto the item. I think I might be referencing enableInteractions incorrectly, because someone else could resolve this issue using the same method:
How do I reference XRBaseInteractor.enableInteractions = false? I’m calling an IEnumerator called “death” when the enemy gets too close, but the player is still able to hold onto the flashlight.
and I drag the Game Object containing the XRDirectInteractable onto “interactor” because I cant reference the XRBaseInteractor directly. But when I test the game, the player is able to hold onto the torch throughout the death sequence. Any ideas? Thank you!
If you have created a derived behavior for the XRBaseInteractor, make sure that you are calling into the base class if you are overriding either the isSelectActive property or CanSelect(XRBaseInteractable) method. If you are overriding those without checking that the allowSelect is false, the Interaction Manager will not know to trigger a deselect.
If you don’t have a custom Interactor and it is still not working, make sure that the death() routine is actually being called. You could set a breakpoint or add a Debug.Log to verify that you are setting the property. If may not actually be getting invoked if you are starting the coroutine on a deactivated GameObject.
Disabling the Interactor component is another way of causing the Interactor to deselect since the Interaction Manager will cancel the select when the Interactor is unregistered upon being disabled.
And just so you’re aware, the XRBaseInteractor.enableInteractions property was deprecated in 1.0.0-pre.3 and XRBaseInteractor.allowHover and XRBaseInteractor.allowSelect should be used instead.