Skip to content

Use hooks for component initialization#483

Merged
Jondolf merged 2 commits into
mainfrom
better-component-initialization
Aug 10, 2024
Merged

Use hooks for component initialization#483
Jondolf merged 2 commits into
mainfrom
better-component-initialization

Conversation

@Jondolf

@Jondolf Jondolf commented Aug 9, 2024

Copy link
Copy Markdown
Member

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 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 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
@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-Bug Something isn't working 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.

Make physics entity creation more difficult to mess up

1 participant