Skip to content

Commit

Permalink
Don't trigger animation events when paused (#15677)
Browse files Browse the repository at this point in the history
# Objective

Pausing the `animated_fox` example perfectly as one of the feet hits the
ground causes the event to be triggered every frame.

Context: #15538

## Solution

Don't trigger animation events if the animation is paused.

## Testing

Ran the example, I no longer see the issue.
  • Loading branch information
atornity authored Oct 6, 2024
1 parent 6edb78a commit 70269ef
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions crates/bevy_animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1143,25 +1143,27 @@ pub fn animate_targets(
continue;
};

// Trigger all animation events that occurred this tick, if any.
if let Some(triggered_events) = TriggeredEvents::from_animation(
AnimationEventTarget::Node(target_id),
clip,
active_animation,
) {
if !triggered_events.is_empty() {
par_commands.command_scope(move |mut commands| {
for TimedAnimationEvent { time, event } in
triggered_events.iter()
{
commands.queue(trigger_animation_event(
entity,
*time,
active_animation.weight,
event.clone().0,
));
}
});
if !active_animation.paused {
// Trigger all animation events that occurred this tick, if any.
if let Some(triggered_events) = TriggeredEvents::from_animation(
AnimationEventTarget::Node(target_id),
clip,
active_animation,
) {
if !triggered_events.is_empty() {
par_commands.command_scope(move |mut commands| {
for TimedAnimationEvent { time, event } in
triggered_events.iter()
{
commands.queue(trigger_animation_event(
entity,
*time,
active_animation.weight,
event.clone().0,
));
}
});
}
}
}

Expand Down

0 comments on commit 70269ef

Please sign in to comment.