Commit e5508b4
Improve Component Hook Ergonomics (#21800)
# Objective
Fixes: #21794
## Solution
- If a hook-path is not provided by the user we insert the default path.
## Testing
Added a doctest (Edit).
Ran and looked at the expanded macro of the following example,
```rust
use bevy_ecs::lifecycle::HookContext;
use bevy_ecs::prelude::*;
use bevy_ecs::world::DeferredWorld;
#[derive(Component)]
#[component(on_add, on_insert, on_despawn, on_remove=on_remove)]
struct Tile;
impl Tile {
fn on_add(_world: DeferredWorld, _context: HookContext) {
println!("added");
}
fn on_insert(_world: DeferredWorld, _context: HookContext) {
println!("inserted");
}
fn on_despawn(_world: DeferredWorld, _context: HookContext) {
println!("despawned");
}
}
fn on_remove(_world: DeferredWorld, _context: HookContext) {
println!("removed");
}
fn main() {
let mut world = World::new();
let entity = world.spawn(Tile);
entity.despawn();
}
```
---------
Co-authored-by: Carter Anderson <[email protected]>1 parent 8d93f10 commit e5508b4
File tree
3 files changed
+51
-11
lines changed- crates/bevy_ecs
- macros/src
- src/component
3 files changed
+51
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
410 | 422 | | |
411 | 423 | | |
412 | 424 | | |
| |||
439 | 451 | | |
440 | 452 | | |
441 | 453 | | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | 454 | | |
449 | 455 | | |
450 | 456 | | |
| |||
566 | 572 | | |
567 | 573 | | |
568 | 574 | | |
569 | | - | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
570 | 578 | | |
571 | 579 | | |
572 | | - | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
573 | 583 | | |
574 | 584 | | |
575 | | - | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
576 | 588 | | |
577 | 589 | | |
578 | | - | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
579 | 593 | | |
580 | 594 | | |
581 | | - | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
582 | 598 | | |
583 | 599 | | |
584 | 600 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
646 | 646 | | |
647 | 647 | | |
648 | 648 | | |
| 649 | + | |
649 | 650 | | |
650 | 651 | | |
651 | 652 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
408 | 431 | | |
409 | 432 | | |
410 | 433 | | |
| |||
0 commit comments