Socket Interaction to Get Things Done

Simon Pham
3 min readNov 28, 2023

--

In this article, let’s discuss a new type of interaction in the Unity XR toolkit: socket interaction and a demo for its uses.

What is a socket interaction?

A socket interaction is type of interaction that allows an object (socket interactor) to grab nearby valid interactable objects, snapping them into place using the socket transform. There are many uses for this including plugging a cable into a socket (which is obvious), inserting a key into a lock, etc.

How to set it up?

Here I have set up a simple scene with a closed door and a key.

Let’s create an interaction between the key an the key hole to open the door.

Key hole and key

The first step is to add an XR Socket Interactor to the key hold object, create a child empty object to acts as an attach point between the key and key hole, and drop it into the Attach Transform field.

Since this is a key hole, we don’t want other objects to interact with it and to prevent this from happening, create a new layer mask called “Key” from the Interaction Layer Mask dropdown list and make sure that it’s value is set to Key only.

Let’s also set the key layer mask to Key.

Door animation trigger

Our door has an Animator component that controls the door’s opening and closing animation and the animation is triggered by the DoorOpen parameter.

Under the XR Socket Interactor component in the key hole object, we have an interactor event called “Select Entered” that will be executed when an object is socketed. Let’s drop the door object into it and select the SetTrigger(string) function and input the parameter for the door animation trigger which is “DoorOpen”.

Testing

Things worked as expected!

--

--

No responses yet