diff --git a/crates/bevy_picking/src/pointer.rs b/crates/bevy_picking/src/pointer.rs index c7209459dd..7da790c26c 100644 --- a/crates/bevy_picking/src/pointer.rs +++ b/crates/bevy_picking/src/pointer.rs @@ -17,7 +17,7 @@ use bevy_window::PrimaryWindow; use uuid::Uuid; -use core::fmt::Debug; +use core::{fmt::Debug, ops::Deref}; use crate::backend::HitData; @@ -71,6 +71,21 @@ pub struct PointerInteraction { pub(crate) sorted_entities: Vec<(Entity, HitData)>, } +impl PointerInteraction { + /// Returns the nearest hit entity and data about that intersection. + pub fn get_nearest_hit(&self) -> Option<&(Entity, HitData)> { + self.sorted_entities.first() + } +} + +impl Deref for PointerInteraction { + type Target = Vec<(Entity, HitData)>; + + fn deref(&self) -> &Self::Target { + &self.sorted_entities + } +} + /// A resource that maps each [`PointerId`] to their [`Entity`] for easy lookups. #[derive(Debug, Clone, Default, Resource)] pub struct PointerMap {