From 71d69960952d029e63fc7bb74dd0afb171122180 Mon Sep 17 00:00:00 2001 From: Christopher Verch Date: Sun, 24 May 2026 22:42:50 -0700 Subject: [PATCH 1/2] add AnimationEventView and events_iter for viewing AnimationClip events --- crates/bevy_animation/src/lib.rs | 35 +++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index b63ef7998dc62..3e77c1f35bf7d 100644 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -214,13 +214,46 @@ impl Hash for AnimationTargetId { #[reflect(Component, Clone)] pub struct AnimatedBy(#[entities] pub Entity); +/// A read-only projection of an animation event. +/// +/// Use this when you need to manually inspect or trigger animation events +/// outside of the standard animation playback system. +pub struct AnimationEventView { + /// The target bone or entity associated with the event. + /// [`None`] means no specific bone was targeted. + pub animation_target_id: Option, + /// The timestamp (in seconds) at which this event is configured to trigger. + pub trigger_time: f32, + /// The function that this animation event would run + pub trigger_fn: Arc, +} + impl AnimationClip { #[inline] /// [`VariableCurve`]s for each animation target. Indexed by the [`AnimationTargetId`]. pub fn curves(&self) -> &AnimationCurves { &self.curves } - + /// Returns an iterator over all animation events in this clip. + /// + /// Generally should not be used unless existing animation events need to be manually triggered + /// for some reason. + /// + /// The iterator yields [`AnimationEventView`], which provide access + /// to the target, timing, and trigger function of each event. + pub fn events_iter(&self) -> impl Iterator + '_ { + self.events.iter().flat_map(|(k, events)| { + let id = match k { + AnimationEventTarget::Root => None, + AnimationEventTarget::Node(node) => Some(*node), + }; + events.iter().map(move |event| AnimationEventView { + animation_target_id: id, + trigger_time: event.time, + trigger_fn: event.event.trigger.0.clone(), + }) + }) + } #[inline] /// Get mutable references of [`VariableCurve`]s for each animation target. Indexed by the [`AnimationTargetId`]. pub fn curves_mut(&mut self) -> &mut AnimationCurves { From 14a609484b712eb96444d83b7f5d69e89cf01522 Mon Sep 17 00:00:00 2001 From: Christopher Verch Date: Mon, 25 May 2026 19:21:12 -0700 Subject: [PATCH 2/2] clarify comments --- crates/bevy_animation/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index 3e77c1f35bf7d..aedcf156f1d49 100644 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -216,7 +216,7 @@ pub struct AnimatedBy(#[entities] pub Entity); /// A read-only projection of an animation event. /// -/// Use this when you need to manually inspect or trigger animation events +/// Use this when you need to manually inspect animation events and run their designated functions /// outside of the standard animation playback system. pub struct AnimationEventView { /// The target bone or entity associated with the event.