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 hooks for component initialization #483

Merged
merged 2 commits into from
Aug 10, 2024
Merged

Conversation

Jondolf
Copy link
Owner

@Jondolf Jondolf commented Aug 9, 2024

Objective

Fixes #475.

Missing components for rigid bodies, colliders, etc. are currently added at specific points in the physics shedule. This means that the world is momentarily in an invalid state before those systems are run, which can even lead to confusing crashes when using methods like query.single() for queries that expect those components to exist.

Solution

Use component hooks for initializing missing components with minimal delay. This also meaningfully simplifies scheduling.

When Bevy gets required components (Soon™), those could be used instead.

Performance

Using hooks appears to be as fast if not faster than the old initialization systems.


Migration Guide

PrepareSet::PreInit has been renamed to PrepareSet::First, and PrepareSet::InitRigidBodies, PrepareSet::InitColliders, and PrepareSet::InitMassProperties have been removed. Most missing components are now initialized by component lifecycle hooks.

CcdPlugin and SpatialQueryPipeline no longer store a schedule and are now unit structs. Instead of SpatialQueryPlugin::new(my_schedule) or SpatialQueryPlugin::default(), just use SpatialQueryPlugin.

@Jondolf Jondolf added C-Bug Something isn't working A-Scheduling Relates to scheduling or system sets 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 Aug 9, 2024
@Jondolf Jondolf changed the title Use hooks and observers for component initialization Use hooks for component initialization Aug 9, 2024
@Jondolf Jondolf merged commit 5041bea into main Aug 10, 2024
4 checks passed
@Jondolf Jondolf deleted the better-component-initialization branch August 10, 2024 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Scheduling Relates to scheduling or system sets C-Breaking-Change This change removes or changes behavior or APIs, requiring users to adapt C-Bug Something isn't working C-Code-Quality Improvements to code readability, maintainability, or best practices
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make physics entity creation more difficult to mess up
1 participant