Skip to content

Use required components for component initialization#541

Merged
Jondolf merged 6 commits into
mainfrom
use-required-components
Nov 2, 2024
Merged

Use required components for component initialization#541
Jondolf merged 6 commits into
mainfrom
use-required-components

Conversation

@Jondolf

@Jondolf Jondolf commented Nov 1, 2024

Copy link
Copy Markdown
Member

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

  • Make Position and Rotation required and rework init_transforms (ran into some ordering issues, so left it to a follow-up)
  • Make force and impulse components optional
  • Make friction and restitution components optional, and default to globally defined default material properties

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>();

@Jondolf Jondolf added M-Migration-Guide A breaking change to Avian's public API that needs to be noted in a migration guide C-Code-Quality Improvements to code readability, maintainability, or best practices labels Nov 1, 2024
@Jondolf Jondolf enabled auto-merge (squash) November 2, 2024 20:50
@Jondolf Jondolf merged commit 7b80830 into main Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Code-Quality Improvements to code readability, maintainability, or best practices M-Migration-Guide A breaking change to Avian's public API that needs to be noted in a migration guide

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant