XR Interactable with MORE control over input handling ....

Hello.

Bare with me since this is my first Unity project. Literally called Hello World. Yikes.

So the issue I am running into is the following.

  • I’ve setup an XR rig with Left and Right controller (XR interactors)
  • I’ve made a Gun with a custom gun script (XR interactable

When I press the trigger I want to call a function in the Gun script. This works but it doesn’t allow much configuration. I’ve seen the action based samples, but I would like to use C# to program some behaviors. Things like Threshold, Hold/Charge, DoubleTriggers, Gestures, Auto-repeat etcetera.

I’ve been able to get this working a little by NOT using the Activation event of the Interactable. But instead I have an InputAction in the Gun script that uses inputAction.ReadValue<float>(). This allowed me to write the logic I want.

However the Gun is now not aware of which hand has picked it up. How should I handle this? I’m aware of how this is supposed to work. The role of the interactor, interactable and the interactionmanager. Would another approach be better to get the flexibility I want?

Is there a way to propagate the Interactor event arguments to the Interactable through the InteractionManager?

Thanks

A few moments later …

Allright so I have something working. It’s not ideal but I guess it’s close enough. What I needed to learn about was the fact you can get the input event arguments as your parameter in your XRInteractable’s event handler. Unity then displays the method you use as your event handler as Dynamic XRBaseInteractor.

This way I have an OnSelectEnter and OnSelectExit handler in my gun script that receives the XRBaseInteractor and checks which hand was used.

    public void Select(XRBaseInteractor xRBaseInteractor)
    {
        var xrController = xRBaseInteractor.gameObject.GetComponent<XRController>();
        if (xrController)
        {
            inputDevice = InputDevices.GetDeviceAtXRNode(xrController.controllerNode);
        }
    }