-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Component lifecycle reorganization and documentation #19543
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
base: main
Are you sure you want to change the base?
Component lifecycle reorganization and documentation #19543
Conversation
…component-lifecycle-reorg
This is a nit: while not strictly contradictory nor inaccurate, these three passages all seem to have been written at different points in time and so come across as inconsistent:
On
Compared to the crate root:
The crate root references immutability to make the hook consistently update data structures while the corresponding method explicitly warns against using them to keep indexes up to date without mentioning immutable components. Similarly the comment on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely an overall improvement and all seems accurate.
|
||
The same move has been done for the more internal (but public) `ComponentId` constants: `ON_ADD`, `ON_INSERT`, `ON_REMOVE`, `ON_REPLACE`, `ON_DESPAWN`. | ||
|
||
The code for hooks (`HookContext`, `ComponentHook`, `ComponentHooks`) has been extracted from the very long `bevy_ecs::components` module, and now lives in the `bevy_ecs::components` module. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code for hooks (`HookContext`, `ComponentHook`, `ComponentHooks`) has been extracted from the very long `bevy_ecs::components` module, and now lives in the `bevy_ecs::components` module. | |
The code for hooks (`HookContext`, `ComponentHook`, `ComponentHooks`) has been extracted from the very long `bevy_ecs::components` module, and now lives in the `bevy_ecs::component_lifecycle` module. |
/// | ||
/// This information is stored in the [`ComponentInfo`] of the associated component. | ||
/// | ||
/// There is two ways of configuring hooks for a component: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// There is two ways of configuring hooks for a component: | |
/// There are two ways of configuring hooks for a component: |
/// 1. Defining the relevant hooks on the [`Component`] implementation | ||
/// 2. Using the [`World::register_component_hooks`] method | ||
/// | ||
/// # Example 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Example 2" made me wonder what happened to example 1
Having recently experienced the process of grep-ing around trying to find the relevant pieces: this is much better! |
Why not component::lifecycle, and have the lifecycle module be a submodule of the component module? |
Objective
I set out with one simple goal: clearly document the differences between each of the component lifecycle events via module docs.
Unfortunately, no such module existed: the various lifecycle code was scattered to the wind.
Without a unified module, it's very hard to discover the related types, and there's nowhere good to put my shiny new documentation.
Solution
bevy_ecs::component_lifecycle
module.Testing
Thanks CI!
Follow-up
OnReplace
. We should consider renaming those. No bikeshedding in my PR though!