bevy/examples/ecs
Zachary Harrold d0c0bad7b4
Split Component::register_component_hooks into individual methods (#17685)
# Objective

- Fixes #17411

## Solution

- Deprecated `Component::register_component_hooks`
- Added individual methods for each hook which return `None` if the hook
is unused.

## Testing

- CI

---

## Migration Guide

`Component::register_component_hooks` is now deprecated and will be
removed in a future release. When implementing `Component` manually,
also implement the respective hook methods on `Component`.

```rust
// Before
impl Component for Foo {
    // snip
    fn register_component_hooks(hooks: &mut ComponentHooks) {
            hooks.on_add(foo_on_add);
    }
}

// After
impl Component for Foo {
    // snip
    fn on_add() -> Option<ComponentHook> {
            Some(foo_on_add)
    }
}
```

## Notes

I've chosen to deprecate `Component::register_component_hooks` rather
than outright remove it to ease the migration guide. While it is in a
state of deprecation, it must be used by
`Components::register_component_internal` to ensure users who haven't
migrated to the new hook definition scheme aren't left behind. For users
of the new scheme, a default implementation of
`Component::register_component_hooks` is provided which forwards the new
individual hook implementations.

Personally, I think this is a cleaner API to work with, and would allow
the documentation for hooks to exist on the respective `Component`
methods (e.g., documentation for `OnAdd` can exist on
`Component::on_add`). Ideally, `Component::on_add` would be the hook
itself rather than a getter for the hook, but it is the only way to
early-out for a no-op hook, which is important for performance.

## Migration Guide

`Component::register_component_hooks` has been deprecated. If you are
manually implementing the `Component` trait and registering hooks there,
use the individual methods such as `on_add` instead for increased
clarity.
2025-02-05 19:33:05 +00:00
..
change_detection.rs Rename track_change_detection flag to track_location (#17075) 2025-01-01 18:43:47 +00:00
component_hooks.rs Split Component::register_component_hooks into individual methods (#17685) 2025-02-05 19:33:05 +00:00
custom_query_param.rs Prefer Display over Debug (#16112) 2024-12-27 00:40:06 +00:00
custom_schedule.rs Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00
dynamic.rs Move #![warn(clippy::allow_attributes, clippy::allow_attributes_without_reason)] to the workspace Cargo.toml (#17374) 2025-01-15 01:14:58 +00:00
ecs_guide.rs Remove everything except Instant from bevy_utils::time (#17158) 2025-01-05 20:36:08 +00:00
event.rs Created an EventMutator for when you want to mutate an event before reading (#13818) 2024-07-08 14:53:06 +00:00
fallible_params.rs Renamed members of ParamWarnPolicy to reflect new behaviour. (#17311) 2025-01-12 05:40:04 +00:00
fallible_systems.rs Fallible systems (#16589) 2024-12-05 22:29:06 +00:00
fixed_timestep.rs aligning public apis of Time,Timer and Stopwatch (#15962) 2024-10-16 21:09:32 +00:00
generic_system.rs Relationships (non-fragmenting, one-to-many) (#17398) 2025-01-18 22:20:30 +00:00
hierarchy.rs Add an example teaching users about custom relationships (#17443) 2025-01-20 23:17:38 +00:00
immutable_components.rs Move hashbrown and foldhash out of bevy_utils (#17460) 2025-01-23 16:46:08 +00:00
iter_combinations.rs aligning public apis of Time,Timer and Stopwatch (#15962) 2024-10-16 21:09:32 +00:00
nondeterministic_system_order.rs Fix non-functional nondeterministic_system_order example (#10719) 2023-11-25 21:13:35 +00:00
observer_propagation.rs Parent -> ChildOf (#17427) 2025-01-20 22:13:29 +00:00
observers.rs Fix window close in example cause panic (#17533) 2025-01-28 05:37:23 +00:00
one_shot_systems.rs Merge Style properties into Node. Use ComputedNode for computed properties. (#15975) 2024-10-18 22:25:33 +00:00
parallel_query.rs Fix window close in example cause panic (#17533) 2025-01-28 05:37:23 +00:00
relationships.rs Add an example teaching users about custom relationships (#17443) 2025-01-20 23:17:38 +00:00
removal_detection.rs Rename trigger.entity() to trigger.target() (#16716) 2024-12-08 21:55:09 +00:00
run_conditions.rs aligning public apis of Time,Timer and Stopwatch (#15962) 2024-10-16 21:09:32 +00:00
send_and_receive_events.rs Prefer Display over Debug (#16112) 2024-12-27 00:40:06 +00:00
startup_system.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
system_closure.rs Prefer Display over Debug (#16112) 2024-12-27 00:40:06 +00:00
system_param.rs Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
system_piping.rs Fix a few typos (#17292) 2025-01-10 22:48:30 +00:00
system_stepping.rs Remove stepping from default features (#12847) 2024-04-03 19:16:02 +00:00