bevy/crates/bevy_animation
Chris Russell 2486343e87
Include AnimationTarget directly in the animation query rather than reading it through the EntityMut (#15413)
# Objective

Improve the performance of animation.  

`animate_targets` only does work for entities with a `AnimationTarget`
component, but the query it uses has no filters and matches all
archetypes, resulting in extra work checking and ignoring every other
entity in the world.

In addition, it uses `EntityMutExcept::get`, which has to look up the
`ComponentId` for `AnimationTarget` each time it's used.

Fixes #15412

## Solution

Instead of `entity_mut.get::<AnimationTarget>()`, add `&AnimationTarget`
to the query and read it directly. This requires adding
`AnimationTarget` to the list of exceptions in the `EntityMutExcept`.
Since the resulting type is getting long, add an alias for it.

This does mean that `AnimationTarget` is no longer available through
`entity`, which means it's not possible to animate the `AnimationTarget`
component itself.

## Testing

I ran performance traces of many_foxes comparing this branch to main.
Red is main, yellow is these changes:


![image](https://github.com/user-attachments/assets/93ef7d70-5103-4952-86b9-312aafc53e5f)
2024-09-27 18:18:03 +00:00
..
src Include AnimationTarget directly in the animation query rather than reading it through the EntityMut (#15413) 2024-09-27 18:18:03 +00:00
Cargo.toml Allow animation clips to animate arbitrary properties. (#15282) 2024-09-23 17:14:12 +00:00
README.md Add README.md to all crates (#13184) 2024-05-02 18:56:00 +00:00

Bevy Animation

License Crates.io Downloads Docs Discord