Capture the pointer with a manipulator
Capture the pointer to ensure an element receives all subsequent pointer events.
Read time 2 minutesLast updated 22 days ago
When you handle pointer input, you might want the control to capture a pointer. When a visual element captures a pointer, Unity sends all the events associated with the pointer to the visual element regardless of whether the pointer hovers over the visual element. For example, if you create a control that receives drag events and captures the pointer, the control still receives drag events regardless of the pointer location.
The class provides a convenient way to capture the pointer. The class is a base class for all manipulators. A manipulator is a class that handles pointer input and sends events to a visual element. For example, the class is a manipulator that sends a when the user clicks on a visual element. After a , some elements must capture the pointer position to ensure it receives all subsequent pointer events, even when the cursor is no longer hovering over the element. For example, when you click on a button, slider, or scroll bar.
ManipulatorManipulatorClickablePointerDownEventPointerDownEventTo capture the pointer, call .
PointerCaptureHelper.CapturePointerTo release the pointer, call . If another element is already capturing the pointer when you call , the element receives a event and loses the capture.
PointerCaptureHelper.ReleasePointerCapturePointer()PointerCaptureOutEventOnly one element in the application can have the capture at any moment. While an element has the capture, it's the target of all subsequent pointer events except mouse wheel events. This only applies to pointer events that don't already have a set target and rely on the dispatch process to determine the target.
For more information, see the Capture events.