pub fn pointer_events(
input_events: MessageReader<'_, '_, PointerInput>,
pointers: Query<'_, '_, &PointerLocation>,
ancestors_query: Query<'_, '_, &ChildOf>,
pointer_map: Res<'_, PointerMap>,
hover_map: Res<'_, HoverMap>,
previous_hover_map: Res<'_, PreviousHoverMap>,
picking_settings: Res<'_, PickingSettings>,
pointer_state: ResMut<'_, PointerState>,
hovered_entity_ancestors: Local<'_, HoveredEntityAncestors>,
sent_leave: Local<'_, HashSet<(PointerId, Entity)>>,
sent_enter: Local<'_, HashSet<(PointerId, Entity)>>,
commands: Commands<'_, '_>,
message_writers: PickingMessageWriters<'_>,
)Expand description
Dispatches interaction events to the target entities.
Within a single frame, events are dispatched in the following order:
Additionally, across multiple frames, the following are also strictly ordered by the interaction state machine:
- When a pointer moves over the target:
Over,Enter,Move,Leave,Out. - When a pointer presses buttons on the target:
Press,Click,Release. - When a pointer drags the target:
DragStart,Drag,DragEnd. - When a pointer drags something over the target:
DragEnter,DragOver,DragDrop,DragLeave. - When a pointer is canceled:
No other events will follow the
Cancelevent for that pointer.
Four events – Over, Enter, Leave and Out – are driven only by the HoverMap.
The rest rely on additional data from the PointerInput event stream. To
receive these events for a custom pointer, you must add PointerInput
events.
When the pointer goes from hovering entity A to entity B, entity A will
receive Out and Enter and then entity B will receive Leave and Over.
No entity will ever receive both an Over and an Out or
an Enter and a Leave event during the same frame.
When we account for event bubbling, the two pairs of events,
Out Over and Enter Leave, behave differently. When the hovering focus shifts
between children, parent entities may receive redundant Out → Over pairs. In
the case of Enter → Leave, shared parent entities will not receive Enter
or Leave.
Both Click and Release target the entity hovered in the previous frame,
rather than the current frame. This is because touch pointers hover nothing
on the frame they are released. The end effect is that these two events can
be received sequentially after an Out event (but always on the same frame
as the Out event).
Note: Though it is common for the PointerInput stream may contain
multiple pointer movements and presses each frame, the hover state is
determined only by the pointer’s final position. Since the hover state
ultimately determines which entities receive events, this may mean that an
entity can receive events from before or after it was actually hovered.