Sitemap

Unity VR: Socket Interactors

4 min readMay 9, 2025

Intro

In this article, we are going to cover how to create a keyhole where a key can be inserted into it. This keyhole will need a collider so it can detect when the key’s collider comes in contact with it.

Make sure ‘IsTrigger’ is enabled so it doesn’t act like a solid sphere but just a trigger volume.

XR Socket Interactor

We are going to attach a Socket Interactor component to the keyhole, which will allow the key to be placed into it. An Socket Interactor (using the XR Interaction Toolkit) allows you to “attach” or “snap” XR Grab Interactable objects into a specific position.

Key Features of XR Socket Interactor:

  • Interaction Filtering: You can control which objects are accepted using the Interaction Layer Mask.
  • Attach Transform: Just like Grab Interactables, you can set an Attach Transform to define the exact position and orientation the object should snap to.
  • Hover and Select Events: Like other interactors, it supports hover and select Unity Events you can hook into for custom feedback (e.g., sound or animation).
  • Hover Materials: Show when an item is compatible/incompatible using different materials.

You can see how the Hover Mesh is rendered in the Socket when the Collider is triggered and once the key is released it snaps into the keyhole’s position and rotation. That is why it is placed backwards. I just want to note that the key has an XR Grab Interactable component to it.

Attach Point

To resolve the positioning problem, we can add an empty child object to the Keyhole. Then, we can rotate and position this child object to define the desired snap-to orientation for the key.

The Socket Interactor component has an Attach Transform field. Assigning the AttachPoint’s Transform to this field will make the Socket Interactor use that AttachPoint’s Transform when a compatible Grab Interactable is placed in it.

Interaction Layer Mask

As it is set up now, the Socket Interactor (keyhole) will accept any kind of Grab interactable. This is due to the Interaction Layer Mask being set to ‘Everything’ or all layers.

The Interaction Layer Mask is a filter that determines which Interactables an Interactor (like a controller or socket) can detect and interact with. It works similarly to Unity’s standard Layer Mask but is specific to the XR Interaction system.

We can create an Interaction Layer Mask (Key) and set the keyhole and key to this layer. This will now prevent any Interactable that are not on the layer from interacting with the Socket Interactor (keyhole).

Conclusion

The XR Socket Interactor allows you to “snap” XR Grab Interactable objects into a specific position, which can be used for:

  • Placing tools or items into a holster or sheath
  • Dropping an object into a machine, puzzle, or container
  • Snapping a key into a lock, or battery into a socket

The XR Socket Interactor, when used with a trigger collider, identifies collisions with compatible XR Grab Interactable objects that are filtered using the Layer Interaction Mask. Using a correctly positioned child object for the Attach Transform will make sure the grabbed object will snap into place with the correct orientation upon release.

--

--

No responses yet