Class
UIDragDetector
Instance which facilitates and encourages interaction with UI elements in an experience.
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#
ActivatedCursorIconContentId | Sets the cursor icon to display when the mouse is activated over the
parent of this UIDragDetector.ReadSafe |
ActivatedCursorIconContentContent | Sets the cursor icon to display when the mouse is activated over the
parent of this UIDragDetector. Only supports asset URIsReadSafe |
BoundingBehaviorUIDragDetectorBoundingBehavior | Determines bounding behavior of the dragged UI object when the detector's
BoundingUI is set.ReadSafe |
BoundingUIGuiBase2d | Instance whose bounding area defines the drag boundaries for the parent
GuiObject.ReadSafe |
CursorIconContentId | Sets the cursor icon to display when the mouse is hovered over the parent
of this UIDragDetector.ReadSafe |
CursorIconContentContent | Sets the cursor icon to display when the mouse is hovered over the parent
of this UIDragDetector. Only asset URIs are supported.ReadSafe |
DragAxisVector2 | The drag axis for the UIDragDetector instance when
DragStyle is set to
UIDragDetectorDragStyle.TranslateLine.ReadSafe |
DragRelativityUIDragDetectorDragRelativity | Sets the paradigm which defines the relativity of inputs/outputs from a custom drag function.ReadSafe |
DragRotationfloat | The rotation performed by the current drag.ReadSafe |
DragSpaceUIDragDetectorDragSpace | Sets the paradigm which defines the space of inputs/outputs from a custom drag function.ReadSafe |
DragStyleUIDragDetectorDragStyle | The paradigm used to generate proposed motion.ReadSafe |
DragUDim2UDim2 | The translation performed by the current drag expressed in a
UDim2 value.ReadSafe |
Enabledboolean | Whether the UIDragDetector responds to user input.ReadSafe |
MaxDragAnglefloat | Along with MinDragAngle, impedes the
detector's attempts to generate rotational motion.ReadSafe |
MaxDragTranslationUDim2 | Along with MinDragTranslation,
impedes the detector's attempts to generate linear/planar motion.ReadSafe |
MinDragAnglefloat | Along with MaxDragAngle, impedes the
detector's attempts to generate rotational motion.ReadSafe |
MinDragTranslationUDim2 | Along with MaxDragTranslation,
impedes the detector's attempts to generate linear/planar motion.ReadSafe |
ReferenceUIInstanceGuiObject | A GuiObject instance whose local space and absolute center
position is the reference space and origin for the detector.ReadSafe |
ResponseStyleUIDragDetectorResponseStyle | The paradigm used to define the response to proposed motion.ReadSafe |
SelectionModeDragSpeedUDim2 | Maximum drag speed for translation.ReadSafe |
SelectionModeRotateSpeedfloat | Maximum angle per second the UIDragDetector can rotate at.ReadSafe |
UIDragSpeedAxisMappingUIDragSpeedAxisMapping | UIDragSpeedAxisMapping value that determines the X/Y
dimension dragging speeds.ReadSafe |
ActivatedCursorIcon: ContentId#
ReadSafe
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: Content#
ReadSafe
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. Only asset URIs are supported for this property.
BoundingBehavior: UIDragDetectorBoundingBehavior#
ReadSafe
Determines bounding behavior of the dragged UI object when the detector's
BoundingUI is set. See
UIDragDetectorBoundingBehavior for details on each setting's
behavior.
BoundingUI: GuiBase2d#
ReadSafe
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.
CursorIcon: ContentId#
ReadSafe
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: Content#
ReadSafe
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: Vector2#
ReadSafe
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.
DragRelativity: UIDragDetectorDragRelativity#
ReadSafe
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 Datatype.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.
DragRotation: float#
ReadSafe
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.
DragSpace: UIDragDetectorDragSpace#
ReadSafe
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:
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: UIDragDetectorDragStyle#
ReadSafe
The paradigm used to generate proposed motion, given a stream of input
position vectors. See UIDragDetectorDragStyle for options.
DragUDim2: UDim2#
ReadSafe
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.
Enabled: boolean#
ReadSafe
If true, the UIDragDetector responds to user input; if false,
it does not.
MaxDragAngle: float#
ReadSafe
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.
MaxDragTranslation: UDim2#
ReadSafe
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.
MinDragAngle: float#
ReadSafe
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.
MinDragTranslation: UDim2#
ReadSafe
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.
ReferenceUIInstance: GuiObject#
ReadSafe
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.
ResponseStyle: UIDragDetectorResponseStyle#
ReadSafe
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.
SelectionModeDragSpeed: UDim2#
ReadSafe
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.
SelectionModeRotateSpeed: float#
ReadSafe
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.
UIDragSpeedAxisMapping: UIDragSpeedAxisMapping#
ReadSafe
UIDragSpeedAxisMapping value that determines the X/Y
dimension dragging speeds.
Methods 4#
| AddConstraintFunction | Adds a function to modify or constrain proposed motion. |
| GetReferencePosition | Returns the reference UDim2 position of the current drag's
reference origin. |
| GetReferenceRotation | Returns the reference rotation of the current drag's reference element. |
| SetDragStyleFunction | Passes a function to be used if and only if
DragStyle is set to
UIDragDetectorDragStyle.Scriptable. |
AddConstraintFunction(priority: int, function: Function): 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.
| Name | Type | Default | Description |
|---|---|---|---|
priority | int | The order of priority for functions added via this method. Higher values take precedence over lower values. | |
function | Function | Function for modifying or constraining proposed motion. This function
takes in input UDim2 and float of proposed motion and
returns a UDim2 and float of modified or unmodified
motion. It can optionally return an
UIDragDetectorDragRelativity and UIDragDetectorDragSpace
as the third and fourth return values as output overrides. |
Returns
RBXScriptConnection— Use this connection object to remove the constraint function.
GetReferencePosition(): 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.
GetReferenceRotation(): 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.
Returns
float— Rotation of the current drag's reference element.
SetDragStyleFunction(function: Function): ()#
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
overridden 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.
| Name | Type | Default | Description |
|---|---|---|---|
function | Function | Function for monitoring
DragContinue signals. This
function receives the signal's screen space input position and returns
a UDim2 and float containing the desired motion of the drag
in the desired space and relativity. If this function returns nil,
the object will not be moved. |
Returns
()
Events 3#
| DragContinue | Fires when a user continues dragging the UI element after
DragStart has been initiated. |
| DragEnd | Fires when a user stops dragging the UI element. |
| DragStart | Fires when a user starts dragging the UI element. |
Inherited members#
Inherited from Instance 58
Properties (10)
Archivable, archivable, Capabilities, IsInSandbox, Name, Parent, PredictionMode, RobloxLocked, Sandboxed, UniqueId
Methods (39)
AddTag, children, ClearAllChildren, Clone, clone, Destroy, destroy, FindFirstAncestor, FindFirstAncestorOfClass, FindFirstAncestorWhichIsA, FindFirstChild, findFirstChild, FindFirstChildOfClass, FindFirstChildWhichIsA, FindFirstDescendant, GetActor, GetAttribute, GetAttributeChangedSignal, GetAttributes, GetChildren, getChildren, GetDebugId, GetDescendants, GetFullName, GetStyled, GetStyledPropertyChangedSignal, GetTags, HasTag, IsAncestorOf, IsDescendantOf, isDescendantOf, IsPropertyModified, QueryDescendants, Remove, remove, RemoveTag, ResetPropertyToDefault, SetAttribute, WaitForChild