Search Unity

Question Can't Trigger an XR Grab Interactable's OnSelectEnter when it activates objects

Discussion in 'XR Interaction Toolkit and Input' started by chazgw, Jan 10, 2022.

  1. chazgw

    chazgw

    Joined:
    Dec 19, 2018
    Posts:
    17
    Here's my scenario: For my XR Rig, I can grab either a gun or a grenade (XR Grab Interactable Objects). By firing the gun, my code activates each individual Bullet object from a pool. After a few seconds, that bullet becomes inactive (SetActive(false)).

    The problem is that every bullet has to deactivate in order to get the ability back to have my XR Controller select anything again. So, if I fire a few bullets with the gun, then let it go in order to trigger OnSelectExit(), I can't get OnSelectEnter to work with anything until those bullets are deactivated. At first I thought it had to do something with the Controller taking "control" of the bullet object, but I shuffled some code around so that the Controller action only calls functions in other classes, and those other classes are responsible for the bullet instantiation.

    What gives? Is there a way around this to make it so that I can fire a few bullets, put down the gun, and throw a grenade immediately? I'm not sure exactly how having an object's OnSelect() can block all further OnSelect()s.
     
  2. chazgw

    chazgw

    Joined:
    Dec 19, 2018
    Posts:
    17
    Well, something in Unity must have gotten corrupted along the way in my scene, because I brought these individual components into a new testing scene, and the expected behavior now works just fine.

    I've also changed the logic to just use the new input system, and not any of the Interactable Events. I'm now checking for whether or not something is selected by using the value of GetComponent<XRBaseInteractable>().isSelected, and only firing a bullet if that's true. Seems to work perfectly.
     
    VRDave_Unity likes this.