Class · inherits UIComponent
UIDragDetector
Instance which facilitates and encourages interaction with UI elements in an experience.
About UIDragDetector
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
UIDragDetectorunder anyGuiObjectinstance to make it draggable via all inputs without a single line of code.Choose from several
DragStyleoptions, define how the object responds to motion viaResponseStyle, 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.
UIDragDetectorswork 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.
Properties 22
ActivatedCursorIcon
: ContentIdSets the cursor icon to display when the mouse is activated over the parent of thisUIDragDetector.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.
ActivatedCursorIconContent
: ContentSets the cursor icon to display when the mouse is activated over the parent of thisUIDragDetector. Only supports asset URIsSets 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. Only asset URIs are supported for this property.
BoundingBehavior
: UIDragDetectorBoundingBehaviorDetermines bounding behavior of the dragged UI object when the detector'sBoundingUIis set.Determines bounding behavior of the dragged UI object when the detector's
BoundingUIis set. SeeUIDragDetectorBoundingBehaviorfor details on each setting's behavior.BoundingUI
: GuiBase2dInstance whose bounding area defines the drag boundaries for the parentGuiObject.When set, the
UIDragDetectorinstance will not allow the bounds of the parentGuiObjectto be dragged outside the bounds of the BoundingUI instance.Note that if a portion of the parent
GuiObjectis 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.CursorIcon
: ContentIdSets the cursor icon to display when the mouse is hovered over the parent of thisUIDragDetector.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.
CursorIconContent
: ContentSets the cursor icon to display when the mouse is hovered over the parent of thisUIDragDetector. Only asset URIs are supported.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. Only asset URIs are supported for this property.
DragAxis
: Vector2The drag axis for theUIDragDetectorinstance whenDragStyleis set toUIDragDetectorDragStyle.TranslateLine.Vector2value that defines the axis of movement for the dragged object whenDragStyleis set toUIDragDetectorDragStyle.TranslateLine. The axis is defined in the local space of theUIDragDetectorunlessReferenceUIInstanceis defined, in which case the axis is defined in that instance's local space.DragRelativity
: UIDragDetectorDragRelativitySets the paradigm which defines the relativity of inputs/outputs from a custom drag function.Only applies if a custom drag function is registered through
SetDragStyleFunction()orAddConstraintFunction(). Sets the paradigm which defines the relativity of the registered function's inputs/outputs.For example, returning a
Datatype.UDim2.fromOffset(1, 0)from a registered function with this property set toUIDragDetectorDragRelativity.Absolutewill move the detector's parent to(1, 0)in the designatedDragSpace, while returning the sameUDim2with this property set toUIDragDetectorDragRelativity.Relativewill move the detector's parent by(1, 0)in the designatedDragSpace.DragRotation
: floatThe rotation performed by the current drag.The rotation performed by the current drag. This value is defined in degrees relative to the local space of the
UIDragDetectorunlessReferenceUIInstanceis 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.
DragSpace
: UIDragDetectorDragSpaceSets the paradigm which defines the space of inputs/outputs from a custom drag function.Only applies if a custom drag function is registered through
SetDragStyleFunction()orAddConstraintFunction(). Sets the paradigm which defines the space of the registered function's inputs/outputs.For example, if the detector's parent
GuiObjectis a child of a parentGuiObjectthat's rotated:Returning a
Datatype.UDim2.fromOffset(1, 0)from a registered function with this property set toUIDragDetectorDragSpace.Parentwill move the detector's parentGuiObjectto the right by 1 pixel in the local space affected by its parent's rotation.Returning a
Datatype.UDim2.fromOffset(1, 0)from a registered function with this property set toUIDragDetectorDragSpace.LayerCollectorwill move the detector's parentGuiObjectto the right by 1 pixel in the space of theLayerCollector.
DragStyle
: UIDragDetectorDragStyleThe paradigm used to generate proposed motion.The paradigm used to generate proposed motion, given a stream of input position vectors. See
UIDragDetectorDragStylefor options.DragUDim2
: UDim2The translation performed by the current drag expressed in aUDim2value.The translation performed by the current drag expressed in a
UDim2value. Translation is done throughOffsetorScalevalue changes depending on theDragRelativityvalue, and it is relative to the detector's local space unless aReferenceUIInstanceis defined.This property can be changed while there is no active drag to move the dragged object.
Enabled
: booleanWhether theUIDragDetectorresponds to user input.If
true, theUIDragDetectorresponds to user input; iffalse, it does not.MaxDragAngle
: floatAlong withMinDragAngle, impedes the detector's attempts to generate rotational motion.If this property is greater than
MinDragAngle, rotation will be clamped within the range ofMinDragAngleandMaxDragAngle. 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
DragStyleisUIDragDetectorDragStyle.Rotate.MaxDragTranslation
: UDim2Along withMinDragTranslation, impedes the detector's attempts to generate linear/planar motion.If the corresponding
Offsetand/orScalevalues are greater than those ofMinDragTranslationin all dimensions, linear/planar translation will be clamped within the range ofMinDragTranslationandMaxDragTranslation.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
DragStyleisUIDragDetectorDragStyle.TranslateLineorUIDragDetectorDragStyle.TranslatePlane.MinDragAngle
: floatAlong withMaxDragAngle, impedes the detector's attempts to generate rotational motion.If this property is less than
MaxDragAngle, rotation will be clamped within the range ofMinDragAngleandMaxDragAngle. 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
DragStyleisUIDragDetectorDragStyle.Rotate.MinDragTranslation
: UDim2Along withMaxDragTranslation, impedes the detector's attempts to generate linear/planar motion.If the corresponding
Offsetand/orScalevalues are less than those ofMaxDragTranslationin all dimensions, linear/planar translation will be clamped within the range ofMinDragTranslationandMaxDragTranslation.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
DragStyleisUIDragDetectorDragStyle.TranslateLineorUIDragDetectorDragStyle.TranslatePlane.ReferenceUIInstance
: GuiObjectAGuiObjectinstance whose local space and absolute center position is the reference space and origin for the detector.A
GuiObjectinstance whose local space and absolute center position is the reference space and origin for the detector. Setting this reference affects properties such asDragUDim2,DragRotation, and the behavior ofDragAxis.ResponseStyle
: UIDragDetectorResponseStyleThe paradigm used to define the response to proposed motion.Once the proposed motion has been computed and potentially constrained, this paradigm is used to deterimine how to move (or not move) the
GuiObjectaffected by theUIDragDetector. SeeUIDragDetectorResponseStylefor options.SelectionModeDragSpeed
: UDim2Maximum drag speed for translation.Defines the maximum drag speed for translation as a combination of
ScaleandOffsetof the first ancestorScreenGuiorSurfaceGuitheUIDragDetectorbelongs to. This value must be positive and any value below0will be clamped to0.SelectionModeRotateSpeed
: floatMaximum angle per second theUIDragDetectorcan rotate at.Defines the maximum angle per second at which the
UIDragDetectorcan rotate. This value must be positive and any value below0will be clamped to0.UIDragSpeedAxisMapping
: UIDragSpeedAxisMappingUIDragSpeedAxisMappingvalue that determines the X/Y dimension dragging speeds.
Methods 4
AddConstraintFunction
(priority: int, function: Function) → RBXScriptConnectionAdds a function to modify or constrain proposed motion.Adds a function to modify or constrain proposed motion. The function takes an input
UDim2(position) and float (rotation) of proposed motion and returns aUDim2and float of modified or unmodified motion. You can add multiple functions which will be called in order bypriority, passing the results along in a chain.The input is expressed in the space defined by the
DragSpaceproperty, either as a delta or the final desired position/rotation based on theDragRelativityproperty. The output should be expressed in the same space and relativity, unless overridden by returning a specifiedUIDragDetectorDragRelativityandUIDragDetectorDragSpaceas the third and fourth return values.To remove an added constraint function, call
Disconnect()on the returned connection object.GetReferencePosition
() → UDim2Returns the referenceUDim2position of the current drag's reference origin.When no
ReferenceUIInstanceis set, this function returns theUDim2position of the dragged object's immediate parentGuiObject(if one exists), or else theUDim2position of the dragged object.When a
ReferenceUIInstanceis set, this function returns theUDim2position of that reference instance.GetReferenceRotation
() → floatReturns the reference rotation of the current drag's reference element.When no
ReferenceUIInstanceis set, this function returns the rotation of the dragged object's immediate parentGuiObject(if one exists), or else the rotation of the dragged object.When a
ReferenceUIInstanceis set, this function returns the rotation of that reference instance.SetDragStyleFunction
(function: Function) → ()Passes a function to be used if and only ifDragStyleis set toUIDragDetectorDragStyle.Scriptable.Passes a function to be used if and only if
DragStyleis set toUIDragDetectorDragStyle.Scriptable. The given function receives the signal's screen space input position with typeVector2, and it returns aUDim2(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 theDragSpaceandDragRelativityproperties, unless overridden by returning a specifiedUIDragDetectorDragRelativityandUIDragDetectorDragSpaceas 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.
Events 3
DragContinue
UIDragDetector.DragContinue:Connect(function(inputPosition))Fires when a user continues dragging the UI element afterDragStarthas been initiated.DragEnd
UIDragDetector.DragEnd:Connect(function(inputPosition))Fires when a user stops dragging the UI element.DragStart
UIDragDetector.DragStart:Connect(function(inputPosition))Fires when a user starts dragging the UI element.
UIDragDetector also has every member of UIComponent. Deprecated and Roblox-only members are hidden.
Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.