bevyengine / bevyengine/bevy

AnimationEvents should also be EntityEvents

Open
#21,473 1 comment 0 reactions 0 assignees View on GitHub
A-Animation C-Feature
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## What problem does this solve or what need does it fill?

This lets observers of AnimationEvnets be entity-local instead of global.

## What solution would you like?

Deriving AnimationEvent should also impl EntityEvent, with the target entity being `event.trigger().animation_player`, which is what the migration guide said to use in lieu of `event.target()`.

## What alternative(s) have you considered?

Using markers to use distinguish entities in global observers.

Also, trying to derive both AnimationEvent and EntityEvent on one struct gives an error about conflicting implementations of Event.

## Additional context

The migration guide implies this should be possible:
```rs
#[derive(AnimationEvent)]
struct SayMessage(String);

animation.add_event(0.2, SayMessage("hello".to_string()));
world.entity_mut(animation_player).observe(|say_message: On| {
println!("played on", say_message.trigger().animation_player);
})
```
However, when using `commands.spawn(...).observe(...)`, it errors that the AnimationEvent isn't an EntityEvent and can't be used for entity observers.

Contributor guide

Open the contributing guide

Research direction

Start with the migration guide example and the AnimationEvent and EntityEvent derive entry points, then trace how commands.spawn(...).observe(...) validates observer event types. Done means an AnimationEvent can be used with an entity observer whose target is event.trigger().animation_player, without conflicting Event implementations.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.