SteamVR TriggerHapticPulse access Solution

With the release of SteamVR plugin 1.2.3 (or possibly from an earlier release) there have been changes to how the controllers are set up in the CameraRig prefab. SteamVr_Controller.cs is where TriggerHapticPulse() is located, but with the update the script no longer inherits from Monobehaviour. It used to be that you’d put this script on the controller (or the prefab already had it) and called it from a custom script that took in an instance of the controller class.

Now the CameraRig uses SteamVR_TrackedObject.cs, which is more generic and most importantly, is missing TriggerHapticPulse.

In my setup I am using SteamVR_TrackedController.cs alongside the tracked object script to access the triggers, touchpad and buttons in my custom script. the tracked controller script does not use any instance of SteamVR_Controller, so it does not have access to TriggerHapticPulse. I attempted to create a new instance of SteamVR_Controller.Device in my custom script to get my controllers vibrating but while I could get vibration in collision the tracked controller script stopped tracking button and trigger events.

Google was not helping me either, every source either lamented developers lack of use of haptic feedback (hrm fancy that) or gave solutions for earlier versions of the plugin. I scoured the update files the Git repo but could not see where these changes had been documented.

So with that here is my solution: take the TriggerHapticPulse function, copy it, and paste it into the tracked controller script. Everything the function requires is within SteamVR_TrackedController.cs, all you have to do is replace the index value with controllerIndex.

Once I did that everything worked perfectly. In my custom script I create an instance of SteamVR_TrackedController, call TriggerHapticPulse with the pulse strength when I require it, and all is well.

Also you no longer have to feed in the correct controller index every time you run the function, which was the case with the original set up. I’m guessing (or more, hoping) in the next plugin update the access issue will be rectified, but for now this will do.

I’ve also implemented a coroutine in my custom script to fade the vibration pulse in and out for when you move in and out of objects. I absolutely recommend doing this as it simulates the increase and release of pressure when you touch and let go of an object in reality and helps with the immersive experience. I’ll likely put a code example of my custom controller script up on GitHub once I’m finished on this project in May.