extends MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler


Denotes a Unity UI Element as being draggable on the UI Canvas.

If a UI Draggable item is set to Restrict To Drop Zone = true then the UI Draggable item must be a child of an element that has the VRTK_UIDropZone script applied to it to ensure it starts in a valid drop zone.

Script Usage:

  • Place the VRTK_UIDraggableItem script on the Unity UI element that is to be dragged.

Inspector Parameters

  • Restrict To Drop Zone: If checked then the UI element can only be dropped in valid a VRTK_UIDropZone object and must start as a child of a VRTK_UIDropZone object. If unchecked then the UI element can be dropped anywhere on the canvas.
  • Restrict To Original Canvas: If checked then the UI element can only be dropped on the original parent canvas. If unchecked the UI element can be dropped on any valid VRTK_UICanvas.
  • Forward Offset: The offset to bring the UI element forward when it is being dragged.

Class Variables

  • public GameObject validDropZone - The current valid drop zone the dragged element is hovering over.

Class Events

  • DraggableItemDropped - Emitted when the draggable item is successfully dropped.
  • DraggableItemReset - Emitted when the draggable item is reset.

Unity Events

Adding the VRTK_UIDraggableItem_UnityEvents component to VRTK_UIDraggableItem 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.

Event Payload

  • GameObject target - The target the item is dragged onto.


VRTK/Examples/034_Controls_InteractingWithUnityUI demonstrates a collection of UI elements that are draggable