Skip to content

Feature: add AnimationEventView and events_iter for viewing AnimationClip events#24437

Open
christopherverch wants to merge 2 commits into
bevyengine:mainfrom
christopherverch:feature/animation-event-view
Open

Feature: add AnimationEventView and events_iter for viewing AnimationClip events#24437
christopherverch wants to merge 2 commits into
bevyengine:mainfrom
christopherverch:feature/animation-event-view

Conversation

@christopherverch
Copy link
Copy Markdown

@christopherverch christopherverch commented May 25, 2026

Objective

A system needs to play animations starting at a certain time, but sometimes you don't want to skip the animation events that came before.

For example, a sword unsheathing should always play the unsheath sound, but sometimes the animation is played from a bit further into the unsheathing for a different starting pose.

Solution

This PR gives a "view" into the animation events, so that if someone needs to manually trigger them, they can. It's a bit awkward to use since it copies the internal trigger fn, but it's still useful enough that it seems worth adding.

Testing

I stuck this code into the animation_events example and it reliably manually triggers both animation events every 0.4 seconds.

fn debug_animations(
    animations: Res<Assets<AnimationClip>>,
    mut commands: Commands,
    mut timer: Local<f32>,
    time: Res<Time>,
) {
    *timer += time.delta_secs();
    if *timer > 0.4 {
        *timer = 0.0;
        for (_id, animation_clip) in animations.iter() {
            let views = animation_clip.events_iter();
            for view in views {
                dbg!(view.animation_target_id);
                dbg!(view.trigger_time);
                (view.trigger_fn)(&mut commands, Entity::PLACEHOLDER, view.trigger_time, 1.0);
            }
        }
    }
}

I understand this is a bit unwieldy, but this seems like an important thing to be able to access.

Comment thread crates/bevy_animation/src/lib.rs Outdated
Comment on lines +219 to +220
/// Use this when you need to manually inspect or trigger animation events
/// outside of the standard animation playback system.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kinda implies that this is a triggerable event, could be clearer

@laundmo laundmo added A-Animation Make things move and change over time S-Needs-Design This issue requires design work to think about how it would best be accomplished labels May 25, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Animation May 25, 2026
@laundmo laundmo added the C-Feature A new feature, making something new possible label May 25, 2026
@laundmo
Copy link
Copy Markdown
Member

laundmo commented May 25, 2026

I added Needs-Design since i'm not sure this is the best solution to the problem, and i can well imagine different solutions being preferred

@christopherverch
Copy link
Copy Markdown
Author

True on both counts, I changed the comments and I agree it is likely not the best solution, but it's definitely usable. It just seems like something that should be easily accessible and this is the best way I could find without making all the underlying structs pub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Animation Make things move and change over time C-Feature A new feature, making something new possible S-Needs-Design This issue requires design work to think about how it would best be accomplished

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

2 participants