Attempt to automatically grab a specified Interactable Object.
VRTK_InteractTouch- The touch component to determine when a valid touch has taken place to denote a use interaction can occur. This must be applied on the same GameObject as this script if one is not provided via the
VRTK_InteractGrab- The grab component to determine when a valid grab has taken place. This must be applied on the same GameObject as this script if one is not provided via the
- Place the
VRTK_ObjectAutoGrabscript on either:
- The GameObject that contains the Interact Touch and Interact Grab scripts.
- Any other scene GameObject and provide a valid
VRTK_InteractTouchcomponent to the
Interact Touchparameter and a valid
VRTK_InteractGrabcomponent to the
Interact Grabparameter of this script.
- Assign the Interactable Object to auto grab to the
Object To Grabparameter on this script.
- If this Interactable Object is a prefab then the
Object Is Prefabparameter on this script must be checked.
- Object To Grab: The Interactable Object that will be grabbed by the Interact Grab.
- Object Is Prefab: If the
Object To Grabis a prefab then this needs to be checked, if the
Object To Grabalready exists in the scene then this needs to be unchecked.
- Clone Grabbed Object: If this is checked then the
Object To Grabwill be cloned into a new Interactable Object and grabbed by the Interact Grab leaving the existing Interactable Object in the scene. This is required if the same Interactable Object is to be grabbed to multiple instances of Interact Grab. It is also required to clone a grabbed Interactable Object if it is a prefab as it needs to exist within the scene to be grabbed.
- Always Clone On Enable: If
Clone Grabbed Objectis checked and this is checked, then whenever this script is disabled and re-enabled, it will always create a new clone of the Interactable Object to grab. If this is unchecked then the original cloned Interactable Object will attempt to be grabbed again. If the original cloned object no longer exists then a new clone will be created.
- Attempt Secondary Grab: If this is checked then the
Object To Grabwill attempt to be secondary grabbed as well as primary grabbed.
- 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.
- Secondary Interact Touch: The secondary controller Interact Touch to listen for touches on. If this field is left blank then it will be looked up on the opposite controller script alias at runtime.
- Secondary Interact Grab: The secondary controller Interact Grab to listen for grab actions on. If this field is left blank then it will be looked up on the opposite controller script alias at runtime.
ObjectAutoGrabCompleted- Emitted when the object auto grab has completed successfully.
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
public virtual void ClearPreviousClone()
The ClearPreviousClone method resets the previous cloned Interactable Object to null to ensure when the script is re-enabled that a new cloned Interactable Object is created, rather than the original clone being grabbed again.
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.
Updated less than a minute ago