Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use required components for component initialization #541

Merged
merged 6 commits into from
Nov 2, 2024

Conversation

Jondolf
Copy link
Owner

@Jondolf Jondolf commented Nov 1, 2024

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 C-Breaking-Change This change removes or changes behavior or APIs, requiring users to adapt 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
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Breaking-Change This change removes or changes behavior or APIs, requiring users to adapt C-Code-Quality Improvements to code readability, maintainability, or best practices
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant