Building a VR simulator using a game pad as input for Unity XR

Hi guys,

I was wondering if a gamepad would be a better input device for simulating VR input over keyboard and mouse, so I built one. :slight_smile:

Here is the result of the prototype:

You can find the scripts on GitHub and a guide on how to set it up in the Wiki.

Releasing objects does not work, yet. In case you figure out how to do it, I would be happy to receive a pull request.

I would like to share some insights with you which I got when building it.

Manipulating the position/orientation of the camera and the game pads was pretty easy. The script controller-control-controller (sorry for this awful name) is very straight forward and easy to implement/understand.

The tricky part was adding button presses. The reason for this can be best understood when looking at this architecture:

The position of the controllers and camera are directly accessible and changeable in the XR Interaction Toolkit component (developer tools), whereas button presses are not directly accessible on this layer (only reacting on them, but not triggering them). To trigger button presses, you have to build a fake controller on the level “provider implementation”. Luckily trzy had a script ready which does exactly this and shared it in thread Unity XR Input: Possible to simulate input events via a fake InputDevice? . I only had to update to the new input system for simpler access to the gamepad inputs.

I’m expecting that the Unity Interaction Toolkit team will release a VR simulator soon which is completely implemented on the bottom layer.

Looking forward to get some feedback!

2 Likes

Hi!

Did you test this in the latest 2020 Unity beta?

The Base Controller object doesn’t exist so you need to create one yourself, but then you get a bunch of errors on each controlller:

NullReferenceException: Object reference not set to an instance of an object
EditorControllerSimulator.LateUpdate () (at Assets/XR/Simulator/Scripts/EditorControllerSimulator.cs:73)

EDIT:
Nm, the errors are there when you don’t have the new input system set up.
However the main issue is that there’s no canvas interaction :(.