Grab Offset Interactables with the XR Interaction Toolkit

David Brown
2 min readAug 19, 2022

--

Objective: Learn how to grab any object while it maintains its position and rotation.

If you're not sure what an offset interactable is, then let me tell you. This interactable allows you to grab an object while it maintains its position and rotation.

Let’s look at the normal XR grab interactable.

As you can see the cube only is able to be grabbed in the same position no matter where I grab it. Thats not very fun is it.

Now let's see how the Offset interactable is like.

The Offset Interactable however does what we want. Now that you see this is way better in every way, create a new C# script called OffsetInteractable and use the code below.

Click here to use the Offset Interactable script

Code Explanation

Create Attach Transform

The awake method calls the CreateAttachTransform method. This method simply creates an attach transform if there isn’t one assigned in the inspector.

An Attach Transform is required for this script to work.

Match Attach Point + Is First Selecting

The IsFirstSelecting bool checks if the object is being grabbed. If it is grabbed, then the method will check if it is a direct interactor.

If is a direct interactor, then the attach transforms position and rotation will be equal to the direct interactors position and rotation. However, if something else grabs it like a ray or socket interactor, it will do the default behavior.

Thanks For Reading!

--

--

David Brown

I like pizza, cream soda, and making games with Unity