Create Grab Interactions
In this tutorial, you learn how to use grab interactions to grab a cube with your hands, controllers, or controller driven hands. If you’re using Interaction SDK v62+ and aren’t using controller driven hands, just hands or controllers, ignore this tutorial and use
Add an Interaction with QuickActions instead. To try grab interactions in a pre-built scene, see the
HandGrabExamples scene.
Grab interactors let you initiate a grab with your hands, controllers, or controller driven hands. There are two types of grab interactor, HandGrabInteractor for hands and controller driven hands, and ControllerGrabInteractor for controllers.
Adding Hand Grab Interactors to Hands - Open the Unity scene where you set up your hands.
Under Project, search for HandGrabInteractor, and drag the HandGrabInteractor prefab from the search results onto OVRInteraction > Hands > LeftHand > HandInteractorsLeft.
- Under Hierarchy, select HandInteractorsLeft.
- Under Inspector, in the Best Hover Interactor Group component, click the + to add a new element to the Interactors list.
Set the element to HandGrabInteractor by dragging HandGrabInteractor from Hierarchy to the element’s field.
- Repeat these steps for the right hand.
Adding Hand Grab Interactors to controller driven hands - Open the Unity scene where you set up your controller driven hands.
Under Project, search for HandGrabInteractor, and drag the HandGrabInteractor prefab from the search results onto ControllerHands > LeftControllerHand > ControllerHandInteractors.
Your hierarchy should look like this.
- Under Hierarchy, select LeftControllerHand > ControllerHandInteractors.
- Under Inspector, in the Best Hover Interactor Group component, click the + to add an element to the Interactors list.
Set the element to HandGrabInteractor.
- Repeat these steps for the right controller hand.
Adding Controller Grab Interactors to Controllers - Open the Unity scene where you set up your controllers.
Under Project, search for ControllerGrabInteractor, and drag the ControllerGrabInteractor prefab from the search results onto Controllers > LeftController > ControllerInteractors.
Your hierarchy should look like this.
- Under Hierarchy, select LeftController > ControllerInteractors.
- Under Inspector, in the Best Hover Interactor Group component, click the + to add an element to the Interactors list.
Set the element to ControllerGrabInteractor.
- Repeat these steps for the right controller.
A grab interactable lets you grab the object it’s attached to. There are two type of grab interactable, one for grabbing objects using controllers, and one for hands and controller driven hands. If you want to grab an object using controllers, the object needs a Grab Interactable component, but to grab an object using hands and controller driven hands, the object needs a Hand Grab Interactable component.
- Add a Cube GameObject to your scene by right-clicking in the Hierarchy and selecting 3D Object > Cube.
- Under Hierarchy, select Cube.
- Under Inspector, in the Transform component, set the X, Y, and Z of the Scale property to 0.1.
- In the scene, position Cube so it’s in front of the camera.
- Under Hierarchy, select Cube.
- Under Inspector, add a RigidBody and a Grabbable component. The Grabbable component is what causes the selected object to move. To learn more, see Grabbable.
- In the Grabbable component, select the Transfer on Second Selection box. This lets you move the object between hands during a grab.
In the Box Collider component, select the Is Trigger checkbox. This stops the cube from floating away when you release it.
In the Rigidbody component, deselect the Use Gravity checkbox.
Under Hierarchy, select Cube.
- Do one of the following depending on the input method you’re using:
- If you’re using hands or controller driven hands, under Inspector, add a Hand Grab Interactable component.
- If you’re using controllers (not controller driven hands), under Inspector, add a Grab Interactable component.
In the Grab Interactable component or Hand Grab Interactable component, set the Pointable Element and RigidBody properties to Cube.
Select File > Build And Run, or if you have a Link connected, click Play.
When the current scene loads, hover over the object, and then make a pinching motion with your hands (if using hands) or press the trigger on the controller (if using controllers or controller driven hands). Your hand or controller grabs the object, which moves with your hand until you open your hand or release the trigger.
Using hands or controller driven hands to grab an object.
Using hands to grab an object.
Note
You can use the Hand Grab Rules to change which fingers start and end a hand grab.
- To learn about the fields of the Hand Grab interaction, see Hand Grab Interactions.
- To change which fingers start and end a hand grab, see Hand Grab Rules.
- To customize how grabbed objects transform, rotate, and scale, see Grabbable.