XRShared Interactions
Existing interaction stacks (XR Interaction Toolkit, Meta Interaction SDK, ...) can be used in a Fusion application. But they are designed for a single user: in a network context, they need some adaptation, for instance to decide who has the authority over a grabbed object, and how the other users see it move.
The XRShared addon keeps this in mind, with two approaches:
- generic interfaces and components, so that the interactions of another stack can be synchronized, and work with the other addons relying on these interfaces (see Synchronizing another interaction stack),
- default interaction modules (grabbing, touch, UI, beams), already handling the network integration: they work out of the box for prototyping or simple projects, and are basic starting points to build upon. They are also crafted to be cross-platform out of the box: they rely on the rig part interfaces, and the default rigs on Unity's generic XR APIs (input devices, XR Hands), so the same interactions work with controllers or hand tracking on the various headsets, and on desktop with the desktop rig.
The default modules and the bridges share the same approach: the interactions are detected on the local user hardware rig, and only their result is synchronized. For instance, a grabbed object follows the network rig part grabbing it (see Rig Architecture).
Fully networked interactions, detected on the network rig, are also possible, and are often a very good choice, if not the best one: the VR Shared sample showcases a fully networked grabbing (see also Remote grabbing). But existing interaction SDKs detect the interactions on the local rig: the hardware based approach fits them better, which makes bridging them to the network simpler.
The default HardwareRig prefab already contains the grabbers, touchers and beams used by these modules (see Rig Setup).
Grabbing
The HardwareBasedGrabbing module is named after its approach: the grabbing is detected on the hardware rig. It works both for networked objects and for objects only used locally (like an object moved in a local menu).

Grabber and Grabbable
A Grabber detects the Grabbable objects in contact with its trigger collider (it requires a rigidbody in its parents, usually kinematic), and grabs them when its rig part grabbing input is on.
It is placed under a hardware rig part implementing IGrabbingProvider, which tells whether the user is grabbing:
HardwareControllergrabs when the grip button of the controller is pressed,XRHandsHardwareHandgrabs when a finger pinch is detected.
A grabber releases its object when its grabbing input stops, and when it is disabled (for instance, a hand losing tracking).
On the Grabbable:
- by default, an object can be grabbed with a hand already closed. With
allowedClosedHandGrabingunchecked, the object has to be hovered before the grabbing input starts, snappingPointTransformplaces the object at a specific position in the hand,- for an object with a non kinematic rigidbody, the rigidbody is kinematic while grabbed, and
applyVelocityOnReleasethrows it with the hand velocity on release, onWillGrab,onGrabandonUngrabevents are called immediately for the local grabbing user, before the state authority is obtained: to react to the networked grab, use theNetworkGrabbableonDidGrabevent.
NetworkGrabbable
A NetworkGrabbable placed next to the Grabbable (the NetworkGrabbable adds it if missing) synchronizes the grab.
The object also needs a NetworkTransform, and a NetworkObject allowing the state authority to change hands: "Allow State Authority Override" checked, "Destroy When State Authority Leaves" and "Is Master Client Object" unchecked.
These are not the NetworkObject defaults, and a spawned prefab with the defaults fails silently.
When the local user grabs the object:
- the
NetworkGrabbablerequests the state authority of the object, if needed, - once it has it, it stores the grabbing
NetworkGrabber(CurrentGrabber) and the grab offsets in networked properties, - during
FixedUpdateNetwork, the state authority moves the object to follow the network grabber, and theNetworkTransformsynchronizes its position.
onDidGrab and onDidUngrab are called for all users.
The NetworkGrabbable also handles:
- extrapolation: for the local user, the object follows the hand, which is itself extrapolated to use the most up to date device position (see "Extrapolation for the local user" in Rig Architecture),
- extrapolation while taking authority (
extrapolateWhileTakingAuthority): while the authority request is pending, the local user already sees the object follow their hand, even if they cannot move itsNetworkTransformyet.
The "grab the world" locomotion is also based on a Grabbable (see Locomotion).
For rigs not built with XRShared, GrabbingSetup adds the grabbers at runtime (see Rig Setup).
Remote grabbing
The RemoteBasedGrabbing module (NetworkHandColliderGrabber, NetworkHandColliderGrabbable) is a teaching example of the fully networked approach: the grabbing is detected on the network rig, without relying on the hardware rig.
It is not used by the default prefabs: use the hardware based grabbing above in XRShared rigs.
The same logic is described in detail, with a working setup, in the VR Shared sample, the initial and simpler version of XRShared.
Physics grabbing
With the default grabbing, a held object is kinematic: it goes through walls and other objects. With physics grabbing (Fusion 2.1 or newer with forecast physics), held objects keep colliding: a held sword stops against a wall or against another user's sword, and the displayed hand stays on its handle. Two follows move the held object toward the hand: force grabbing (ForcePhysicsGrabbable and NetworkForcePhysicsGrabbable), for physical objects that obstacles can push back, and velocity grabbing (VelocityPhysicsGrabbable and NetworkVelocityPhysicsGrabbable), for objects that must follow the hand whatever their mass. See Physics Grabbing.
Touch
A Toucher, placed on the index tip of the hands in the default rigs, detects the touchable objects in contact with it: a Touchable triggers touch events with audio and haptic feedback, and a TouchableButton acts as a press, toggle or radio button.
The touch events are local: the toucher is on the local user hardware rig, so they are only triggered on the touching user's client. To share their result with the other users, the callbacks have to change a networked state.
See Touch & Hover for the details, including touchers for rigs not built with XRShared.
UI
Hands and controllers can interact with Unity UI canvases:
- add an
XSCInputModuleon the sceneEventSystem, - add an
XSCTrackedDeviceRaycasteron each world space canvas. ATrackedDeviceRaycasterwould also work: this subclass mostly ensures that the canvas event camera is set.
The XSCInputModule handles interaction tips (IInteractionTip):
- the
IndexTipMarkerof a hand or simulated hand: the user touches the UI with their finger. It is also a position modifier, so that the hand seems blocked by the UI while pressing it (see "Position modifiers" in Rig Architecture), - the
RayBeamerof a controller: the user points at the UI, selects with the trigger, and scrolls with the joystick.
The "Interactions_UI" sample (Samples/Interactions_UI/Scenes/DemoUI.unity) shows it.
To synchronize the state of UI elements between users, see the UI Synchronization addon.
Beam interactions
The controller beams (RayBeamer, see Locomotion) can also touch and hover objects at a distance, with a BeamToucher and a BeamHoverer placed on the controller, above the beamer: see "Beam touch and hover" in Touch & Hover.
The "BeamerTouch" sample (Samples/Interactions_Beamer/Scenes/Beamer.unity) shows them.
Synchronizing another interaction stack
To synchronize the grabbing logic of another interaction stack, the XRShared Core module defines a grabbable object, with the IGrabbable and INetworkGrabbable interfaces, and a default NetworkGrabber component, representing a rig part able to grab objects on a network rig.
A grabbable of another stack is made networked by a component implementing INetworkGrabbable, next to it, like the NetworkGrabbable of the default grabbing: when the local user grabs the object, it requests the state authority of the object, and stores the grabbing NetworkGrabber in a networked property, while a NetworkTransform synchronizes the object position. Addons relying on these interfaces then know who grabs the object, whatever the stack.
Two addons provide such a bridge, and can serve as examples for other stacks:
- the XR Interaction Toolkit integration addon:
XRITNetworkGrabbable, for the XR Interaction ToolkitXRGrabInteractable, - the Meta Core integration addon:
MetaXRSharedGrabbable, for the Meta Interaction SDKGrabbable(when the Meta Interaction SDK is installed). ItsDemoMetaGrabbingsample scene shows it.
Last updated on
Back to top