Jondolf / avian

ECS-driven 2D and 3D physics engine for the Bevy game engine.
https://crates.io/crates/avian3d
Apache License 2.0
1.54k stars 120 forks source link

Use required components for component initialization #541

Closed Jondolf closed 2 weeks ago

Jondolf commented 3 weeks ago

Objective

Bevy 0.15 got support for required components! We can replace a lot of our custom-made automatic component insertion with them, reducing the number of archetype moves and making startup more efficient.

Solution

Use required components for most component initialization logic.

I have also made CollidingEntities optional, as adding it automatically for every collider wastes memory unnecessarily. It must now be added manually.

Follow-ups


Migration Guide

The CollidingEntities component is no longer added automatically. To read entities that are colliding with a given entity, you must now add the CollidingEntities component for it manually.

To revert to the old behavior, you can also make CollidingEntities a required component for colliders:

app.register_required_components::<Collider, CollidingEntities>();