Guides
These docs are for v3.2.0. Click to read the latest docs for v3.3.0.

VRTK_ObjectAutoGrab

Overview

It is possible to automatically grab an Interactable Object to a specific controller by applying the Object Auto Grab script to the controller that the object should be grabbed by default.

Inspector Parameters

  • Object To Grab: A game object (either within the scene or a prefab) that will be grabbed by the controller on game start.
  • Object Is Prefab: If the Object To Grab is a prefab then this needs to be checked, if the Object To Grab already exists in the scene then this needs to be unchecked.
  • Clone Grabbed Object: If this is checked then the Object To Grab will be cloned into a new object and attached to the controller leaving the existing object in the scene. This is required if the same object is to be grabbed to both controllers as a single object cannot be grabbed by different controllers at the same time. It is also required to clone a grabbed object if it is a prefab as it needs to exist within the scene to be grabbed.
  • Always Clone On Enable: If Clone Grabbed Object is checked and this is checked, then whenever this script is disabled and re-enabled, it will always create a new clone of the object to grab. If this is false then the original cloned object will attempt to be grabbed again. If the original cloned object no longer exists then a new clone will be created.
  • Interact Touch: The Interact Touch to listen for touches on. If the script is being applied onto a controller then this parameter can be left blank as it will be auto populated by the controller the script is on at runtime.
  • Interact Grab: The Interact Grab to listen for grab actions on. If the script is being applied onto a controller then this parameter can be left blank as it will be auto populated by the controller the script is on at runtime.

Class Events

  • ObjectAutoGrabCompleted - Emitted when the object auto grab has completed successfully.

Unity Events

Adding the VRTK_ObjectAutoGrab_UnityEvents component to VRTK_ObjectAutoGrab object allows access to UnityEvents that will react identically to the Class Events.

  • All C# delegate events are mapped to a Unity Event with the On prefix. e.g. MyEvent -> OnMyEvent.

Class Methods

ClearPreviousClone/0

public virtual void ClearPreviousClone()

  • Parameters
  • none
  • Returns
  • none

The ClearPreviousClone method resets the previous cloned object to null to ensure when the script is re-enabled that a new cloned object is created, rather than the original clone being grabbed again.

Example

VRTK/Examples/026_Controller_ForceHoldObject shows how to automatically grab a sword to each controller and also prevents the swords from being dropped so they are permanently attached to the user's controllers.