Reference API Roblox

Engine API

Website

Related

Reference API Roblox

UIDragDetector

Instance which facilitates and encourages interaction with UI elements in an experience.

Member index 27

HistoryMember
645ActivatedCursorIcon: ContentId
635BoundingBehavior: UIDragDetectorBoundingBehavior
629BoundingUI: GuiBase2d
645CursorIcon: ContentId
629DragAxis: Vector2
629DragRelativity: UIDragDetectorDragRelativity
629DragRotation: float
629DragSpace: UIDragDetectorDragSpace
629DragStyle: UIDragDetectorDragStyle
629DragUDim2: UDim2
629Enabled: bool
629MaxDragAngle: float
629MaxDragTranslation: UDim2
629MinDragAngle: float
629MinDragTranslation: UDim2
629ReferenceUIInstance: GuiObject
629ResponseStyle: UIDragDetectorResponseStyle
645SelectionModeDragSpeed: UDim2
645SelectionModeRotateSpeed: float
645UIDragSpeedAxisMapping: UIDragSpeedAxisMapping
629AddConstraintFunction(priority: int, function: Function): RBXScriptConnection
629GetReferencePosition(): UDim2
629GetReferenceRotation(): float
629SetDragStyleFunction(function: Function): null
629DragContinue(inputPosition: Vector2)
629DragEnd(inputPosition: Vector2)
629DragStart(inputPosition: Vector2)
inherited from Instance
553Archivable: bool
635Capabilities: SecurityCapabilities
553Name: string
553Parent: Instance
635Sandboxed: bool
616UniqueId: UniqueId
576AddTag(tag: string): null
573ClearAllChildren(): null
462Clone(): Instance
573Destroy(): null
486FindFirstAncestor(name: string): Instance
486FindFirstAncestorOfClass(className: string): Instance
486FindFirstAncestorWhichIsA(className: string): Instance
486FindFirstChild(name: string, recursive: bool = false): Instance
486FindFirstChildOfClass(className: string): Instance
486FindFirstChildWhichIsA(className: string, recursive: bool = false): Instance
486FindFirstDescendant(name: string): Instance
563GetActor(): Actor
486GetAttribute(attribute: string): Variant
462GetAttributeChangedSignal(attribute: string): RBXScriptSignal
631GetAttributes(): Dictionary
648GetChildren(): Instances
462GetDebugId(scopeLength: int = 4): string
486GetDescendants(): Array
486GetFullName(): string
641GetStyled(name: string): Variant
576GetTags(): Array
576HasTag(tag: string): bool
486IsAncestorOf(descendant: Instance): bool
486IsDescendantOf(ancestor: Instance): bool
580IsPropertyModified(name: string): bool
573Remove(): null
576RemoveTag(tag: string): null
580ResetPropertyToDefault(name: string): null
573SetAttribute(attribute: string, value: Variant): null
462WaitForChild(childName: string, timeOut: double): Instance
648children(): Instances
553clone(): Instance
573destroy(): null
553findFirstChild(name: string, recursive: bool = false): Instance
648getChildren(): Instances
553isDescendantOf(ancestor: Instance): bool
573remove(): null
462AncestryChanged(child: Instance, parent: Instance)
462AttributeChanged(attribute: string)
462ChildAdded(child: Instance)
462ChildRemoved(child: Instance)
462DescendantAdded(descendant: Instance)
462DescendantRemoving(descendant: Instance)
500Destroying()
553childAdded(child: Instance)
inherited from Object
647ClassName: string
647className: string
647GetPropertyChangedSignal(property: string): RBXScriptSignal
647IsA(className: string): bool
650isA(className: string): bool
647Changed(property: string)

Description

The UIDragDetector instance facilitates and encourages interaction with 2D user interface elements in an experience, such as sliders and spinners. Key features include:

  • Place a UIDragDetector under any GuiObject instance to make it draggable via all inputs without a single line of code.

  • Choose from several DragStyle options, define how the object responds to motion via ResponseStyle, and optionally apply axis, movement limits, or drag boundaries.

  • Scripts can respond to manipulation of dragged objects to drive logic responses, such as adjusting settings.

  • UIDragDetectors work in Studio as long as you're not using the Select, Move, Scale, or Rotate tools, nor certain plugins or Studio's UI editor tools.

History 32

Members 27

ActivatedCursorIcon

TypeDefault
ContentId

Sets the cursor icon to display when the mouse is activated over the parent of this UIDragDetector. If this property is left blank, the detector will use the default icon.

To change the activated cursor icon, set this property to the asset ID of the image you'd like to use.

History 2

AddConstraintFunction

Parameters (2)
priorityint
functionFunction
Returns (1)
RBXScriptConnection

Adds a function to modify or constrain proposed motion. The function takes an input UDim2 (position) and float (rotation) of proposed motion and returns a UDim2 and float of modified or unmodified motion. You can add multiple functions which will be called in order by priority, passing the results along in a chain.

The input is expressed in the space defined by the DragSpace property, either as a delta or the final desired position/rotation based on the DragRelativity property. The output should be expressed in the same space and relativity, unless overridden by returning a specified UIDragDetectorDragRelativity and UIDragDetectorDragSpace as the third and fourth return values.

To remove an added constraint function, call Disconnect() on the returned connection object.

History 1

BoundingBehavior

TypeDefault
UIDragDetectorBoundingBehaviorAutomatic

Determines bounding behavior of the dragged UI object when the detector's BoundingUI is set. See UIDragDetectorBoundingBehavior for details on each setting's behavior.

History 1

BoundingUI

TypeDefault
GuiBase2d

When set, the UIDragDetector instance will not allow the bounds of the parent GuiObject to be dragged outside the bounds of the BoundingUI instance.

Note that if a portion of the parent GuiObject is outside the BoundingUI bounds, the initial input position at drag start and its relative position during drag will be used for bounding detection until the entirety of the dragged object is within the bounds, after which the object will be constrained inside the bounds.

History 1

CursorIcon

TypeDefault
ContentId

Sets the cursor icon to display when the mouse is hovered over the parent of this UIDragDetector. If this property is left blank, the detector will use the default icon.

To change the cursor icon, set this property to the asset ID of the image you'd like to use.

History 2

DragAxis

TypeDefault
Vector21, 0

Vector2 value that defines the axis of movement for the dragged object when DragStyle is set to UIDragDetectorDragStyle.TranslateLine. The axis is defined in the local space of the UIDragDetector unless ReferenceUIInstance is defined, in which case the axis is defined in that instance's local space.

History 1

DragContinue

Parameters (1)
inputPositionVector2

Fires when a user continues dragging the UI element after DragStart has been initiated.

History 1

DragEnd

Parameters (1)
inputPositionVector2

Fires when a user stops dragging the UI element.

History 1

DragRelativity

TypeDefault
UIDragDetectorDragRelativityAbsolute

Only applies if a custom drag function is registered through SetDragStyleFunction() or AddConstraintFunction(). Sets the paradigm which defines the relativity of the registered function's inputs/outputs.

For example, returning a UDim2.fromOffset(1, 0) from a registered function with this property set to UIDragDetectorDragRelativity.Absolute will move the detector's parent to (1, 0) in the designated DragSpace, while returning the same UDim2 with this property set to UIDragDetectorDragRelativity.Relative will move the detector's parent by (1, 0) in the designated DragSpace.

History 1

DragRotation

TypeDefault
float0

The rotation performed by the current drag. This value is defined in degrees relative to the local space of the UIDragDetector unless ReferenceUIInstance is defined, in which case the rotation is defined in the local space of that instance and from its positive X axis.

This property can be changed while there is no active drag to rotate the dragged object.

History 1

DragSpace

TypeDefault
UIDragDetectorDragSpaceParent

Only applies if a custom drag function is registered through SetDragStyleFunction() or AddConstraintFunction(). Sets the paradigm which defines the space of the registered function's inputs/outputs.

For example, if the detector's parent GuiObject is a child of a parent GuiObject that's rotated:

History 1

DragStart

Parameters (1)
inputPositionVector2

Fires when a user starts dragging the UI element.

History 1

DragStyle

TypeDefault
UIDragDetectorDragStyleTranslatePlane

The paradigm used to generate proposed motion, given a stream of input position vectors. See UIDragDetectorDragStyle for options.

History 1

DragUDim2

TypeDefault
UDim2{0, 0}, {0, 0}

The translation performed by the current drag expressed in a UDim2 value. Translation is done through Offset or Scale value changes depending on the DragRelativity value, and it is relative to the detector's local space unless a ReferenceUIInstance is defined.

This property can be changed while there is no active drag to move the dragged object.

History 1

Enabled

TypeDefault
booltrue

If true, the UIDragDetector responds to user input; if false, it does not.

History 1

GetReferencePosition

Parameters (0)
No parameters.
Returns (1)
UDim2

When no ReferenceUIInstance is set, this function returns the UDim2 position of the dragged object's immediate parent GuiObject (if one exists), or else the UDim2 position of the dragged object.

When a ReferenceUIInstance is set, this function returns the UDim2 position of that reference instance.

History 1

GetReferenceRotation

Parameters (0)
No parameters.
Returns (1)
float

When no ReferenceUIInstance is set, this function returns the rotation of the dragged object's immediate parent GuiObject (if one exists), or else the rotation of the dragged object.

When a ReferenceUIInstance is set, this function returns the rotation of that reference instance.

History 1

MaxDragAngle

TypeDefault
float0

If this property is greater than MinDragAngle, rotation will be clamped within the range of MinDragAngle and MaxDragAngle. Positive values impede clockwise rotation while negative values impede counterclockwise rotation.

This is not a constraint; it merely impedes the detector's attempts to generate motion in order to remain within limits. See AddConstraintFunction() to add custom constraint to a drag.

Only relevant if DragStyle is UIDragDetectorDragStyle.Rotate.

History 1

MaxDragTranslation

TypeDefault
UDim2{0, 0}, {0, 0}

If the corresponding Offset and/or Scale values are greater than those of MinDragTranslation in all dimensions, linear/planar translation will be clamped within the range of MinDragTranslation and MaxDragTranslation.

This is not a constraint; it merely impedes the detector's attempts to generate motion in order to remain within limits. See AddConstraintFunction() to add custom constraint to a drag.

Only relevant if DragStyle is UIDragDetectorDragStyle.TranslateLine or UIDragDetectorDragStyle.TranslatePlane.

History 1

MinDragAngle

TypeDefault
float0

If this property is less than MaxDragAngle, rotation will be clamped within the range of MinDragAngle and MaxDragAngle. Positive values impede clockwise rotation while negative values impede counterclockwise rotation.

This is not a constraint; it merely impedes the detector's attempts to generate motion in order to remain within limits. See AddConstraintFunction() to add custom constraint to a drag.

Only relevant if DragStyle is UIDragDetectorDragStyle.Rotate.

History 1

MinDragTranslation

TypeDefault
UDim2{0, 0}, {0, 0}

If the corresponding Offset and/or Scale values are less than those of MaxDragTranslation in all dimensions, linear/planar translation will be clamped within the range of MinDragTranslation and MaxDragTranslation.

This is not a constraint; it merely impedes the detector's attempts to generate motion in order to remain within limits. See AddConstraintFunction() to add custom constraint to a drag.

Only relevant if DragStyle is UIDragDetectorDragStyle.TranslateLine or UIDragDetectorDragStyle.TranslatePlane.

History 1

ReferenceUIInstance

TypeDefault
GuiObject

A GuiObject instance whose local space and absolute center position is the reference space and origin for the detector. Setting this reference affects properties such as DragUDim2, DragRotation, and the behavior of DragAxis.

History 1

ResponseStyle

TypeDefault
UIDragDetectorResponseStyleOffset

Once the proposed motion has been computed and potentially constrained, this paradigm is used to deterimine how to move (or not move) the GuiObject affected by the UIDragDetector. See UIDragDetectorResponseStyle for options.

History 1

SelectionModeDragSpeed

TypeDefault
UDim2{0, 300}, {0, 300}

Defines the maximum drag speed for translation as a combination of Scale and Offset of the first ancestor ScreenGui or SurfaceGui the UIDragDetector belongs to. This value must be positive and any value below 0 will be clamped to 0.

History 1

SelectionModeRotateSpeed

TypeDefault
float90

Defines the maximum angle per second at which the UIDragDetector can rotate. This value must be positive and any value below 0 will be clamped to 0.

History 1

SetDragStyleFunction

Parameters (1)
functionFunction
Returns (1)
null

Passes a function to be used if and only if DragStyle is set to UIDragDetectorDragStyle.Scriptable. The given function receives the signal's screen space input position with type Vector2, and it returns a UDim2 (position) and float (rotation) containing the desired motion of the drag. The space of the return values and the relativity of the motion are determined by the DragSpace and DragRelativity properties, unless overriden by returning a specified UIDragDetectorDragRelativity and UIDragDetectorDragSpace as the third and fourth return values.

If the function returns nil, the object will not be moved. This is useful if the script has not yet collected all the information it needs to give the correct answer, or in temporary cases where you want the object to stay where it is.

History 1

UIDragSpeedAxisMapping

TypeDefault
UIDragSpeedAxisMappingXY

UIDragSpeedAxisMapping value that determines the X/Y dimension dragging speeds.

History 1

Settings