In a regular Unity project, you can have a Player Input component that can invoke UnityEvents when an input action happens. This way you don’t need an Update()
function that constantly checks if a button is pressed or not.
My question is how to do this in a XR project? In the screenshot you can see the default XR Origin setup. But there is no player input component here. I don’t see any option to call a UnityEvent once an action from the inputmap happens.
Should I attach another PlayerInput here or will this conflict with all the existing components on the XR Origin?
You should be able to use the Player Input component in addition to the Input Action Manager component.
The Input Action Manager component from the XR Interaction Toolkit has very simple logic where it just enables all input actions (across all input maps) in the referenced Input Action Asset during the component’s own OnEnable
method. It does this because input actions are not enabled by default (with the exception of project-wide actions), so if the input action was read without it being enabled, it would just return the default value.
Since the XR Origin (XR Rig) GameObject needs to read inputs from actions defined in the XRI Default Input Actions asset, even to drive the Transform poses from the HMD, that component is added so all the input actions are enabled automatically at startup.
The Player Input component from Input System will only enable the input actions contained in a single input map, specified by the Default Map dropdown in the Inspector window. But it should allow you to add callbacks as you showed in the first screenshot.
You also aren’t required to use either component. As long as the input actions needed to be read are enabled, it should work fine. You can manage their enabled status yourself through scripting. You can also directly serialize references to specific input actions you want to read from in your script itself using the InputActionReference type and add your callbacks in code or read from them directly. Finally, instead of serializing a reference you can also get a reference at runtime by looking them up by name, see the Input System documentation for Using project-wide actions in code, though you may want to wait for Input System 1.11.0 to be released which contains a bug fix with project-wide actions with the XRI actions.