Package for Unity XR Interaction Toolkit v3.x which enables haptics actuation for Unity canvas IPointer UI events via the SimpleHapticFeedback script.
The best way to install the package is via the Unity Package Manager using the Git URL.
Open Packages/manifest.json
with your favorite text editor. Add following line to the dependencies block:
{
"dependencies": {
"com.uxvirtual.xri-canvas-haptics": "https://github.com/uxvirtual/xri-canvas-haptics.git?path=/com.uxvirtual.xri-canvas-haptics"
}
}
Open Packages/manifest.json
with your favorite text editor. Add a scoped registry and following line to dependencies block:
{
"scopedRegistries": [
{
"name": "npmjs",
"url": "https://registry.npmjs.org/",
"scopes": [
"com.uxvirtual"
]
}
],
"dependencies": {
"com.uxvirtual.xri-canvas-haptics": "1.0.0"
}
}
Package should now appear in package manager.
The package is also available on the openupm registry. You can install it eg. via openupm-cli.
openupm add com.uxvirtual.xri-canvas-haptics
You can open a preconfigured Unity 6 project from Samples/XRICanvasHapticsTester
, otherwise try the following:
- Import XR Interaction Toolkit v3.x and all required dependencies.
- Import the Starter Assets sample from the XR Interaction Toolkit package.
- Import the Haptics Starter sample from the XRI Canvas Haptics package.
- Import XR Interaction Toolkit v3.x and all required dependencies.
- Import the Starter Assets sample from the XR Interaction Toolkit package.
- Create a new Unity scene.
- Add the XR Origin (XR Rig) prefab from the Starter Assets sample to your scene.
- Add the Manual Haptics Manager script from the XRI Canvas Haptics package to the XR Rig.
- Add the Canvas Haptic Manager script to each canvas that you wish to activate haptic interaction on. This canvas should contain UI elements such Buttons, Sliders, Input fields etc as its children. This will search down multiple levels to find all descendents.
- Set the Button Container reference in the Canvas Haptic Manager script to a GameObject that contains Buttons anywhere in its heirarchy.
- Set the Manual Haptics Manager reference to the script that was placed on your XR Rig. If you don't set this or your XR Rig is instantiated later, you will need to update this reference on each Canvas UI that has Canvas Haptic Manager attached.
- Create a new GameObject called
Event System
and add Event System and XR UI Input Module components to it. This is required for the UI Element Haptic Helper to hook into the Event System when interactors select or hover over Buttons in UI Canvases. - (optional) Manually add UI Element Haptic Helper script to any Buttons, Sliders, Input fields for fine control over which child UI element GameObjects will activate haptics. This should work with any UI element that implements
IPointerEnterHandler
,IPointerExitHandler
,IPointerDownHandler
andIPointerUpHandler
.
- (optional) Add and configure an additional SimpleHapticFeedback script to the Near-Far and Poke interactors on the Left and Right Hand GameObjects in the Hands Interaction Demo sample from the Unity XR Interaction Toolkit.
- Start SteamVR and/or connect your XR headset to another OpenXR runtime.
- Test the scene by starting Play Mode in the Unity Editor, the buttons should have a Key Haptics Helper script added to them. This observes any interactions with the Button UI element and triggers haptic effects on the current Near-Far or Poke interactors that have a SimpleHapticFeedback script added to the interactor.
See CONTRIBUTING.md for a guide on how to contribute fixes or features back to this project.
The package can optionally be set as testable. In practice this means that tests in the package will be visible in the Unity Test Runner.
Open Packages/manifest.json
with your favorite text editor. Add following line after the dependencies block:
{
"dependencies": {
},
"testables": [ "com.uxvirtual.xri-canvas-haptics" ]
}
MIT License
Copyright © 2025 UXVirtual