Made With Unity | Unity VR Part 2: Interactors

Rehtse Studio
4 min readMay 12, 2022

Small series of articles / tutorials in getting to know VR on Unity and using the Oculus Quest headset.

Interactors

There are two Interactor components that Unity gives us with OpenXR, XR Ray Interactor and XR Direct Interactor

XR Ray Interactor

The XR Ray Interactor is the one you have by default when you add a XR Origin (Action-Based) on your scene, the red stick ray that moves with your controllers; this allows you to interact with object that can be far away if the red ray touch them.

The rays will interact with whatever object has the component XR Grab Interactable and the appropriate Interaction Layer Mask.

Example In Using XR Ray Interactor And XR Grab Interactable

On the scene I have a 3 object, a Cube, a Sphere and a Cylinder. The Cube has the component script XR Grab Interactable, by adding the script it will automatically add a Rigidbody component to the object. Leaving everything has default notice that both controllers can interact with the just the Cube but not with the other objects. The Cube has the Interaction Layer Mask has Default, is one of the layer that the controllers can interact.

Lets do another example:

Add the remaining objects, Sphere and Cylinder, the XR Grab Interactable and select Interaction Layer Mask, press Add layer… On the following windows put on User Layer 1 to 3 the names of the objects.

On each object, give them there named layer and disable the other one, the following image has the Cube object with just the Cube layer.

Back to the XR Origin game object on the LeftHand Controller set the Interaction Layer Mask to Cube, Cylinder and Sphere; the RightHand Controller will have just the Sphere in the Interaction Layer Mask.

LeftHand Controller can interact with all 3 objects
RightHand Controller can only interact with the Sphere

On this example the LeftHand Controller can interact with all the object because is sharing the same layer, the RightHand Controller can only interact with the Sphere.

If you like to grab a object in a specific spot all you have to do is add a Empty Game Object has a child of the desire object to pick,, named it AttachTransform, place it where it needs to be and put it on the field Attach Transform in the XR Grab Interactable script component.

XR Direct Interactor

The XR Direct Interactor behaves similar to the XR Ray Interactor, if it shares the same layers as the object to interact is going to pick it up. The key difference is that you need to be near the object to be able to interact with it. To use the XR Direct Interactor you will only need the XR Controller (Action-based) script and the XR Direct Interactor on the same game object.

I added a Sphere game object as a child on both LeftHand and RightHand Direct and called it MockHand, I give it a material color and remove the colliders on the Sphere. The LeftHand and RightHand Direct will have a Sphere Collider and it will have Is Trigger Enable. Added the necessary layers on the Interaction Layer Mask.

Next up will be learning some concepts on movements, turns and teleportation.

🎮PART 3🎮

--

--

Rehtse Studio

Game Developer sharing content around Unity, programing and tips and tricks in game dev.