Skip to content

Conversation

@VasanthakumarV
Copy link
Contributor

@VasanthakumarV VasanthakumarV commented Nov 10, 2025

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,

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();
}

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Nov 10, 2025
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I quite like this change, but it needs doc tests, both to ensure that it keeps working, and to make sure that it's discoverable.

Copy link
Member

@cart cart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it!

@cart cart enabled auto-merge November 12, 2025 20:50
@cart cart added this to the 0.18 milestone Nov 12, 2025
@cart cart disabled auto-merge November 12, 2025 22:38
@cart cart enabled auto-merge November 12, 2025 22:38
@cart cart dismissed alice-i-cecile’s stale review November 12, 2025 22:56

This has been addressed

@cart cart added this pull request to the merge queue Nov 12, 2025
Merged via the queue into bevyengine:main with commit e5508b4 Nov 12, 2025
35 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Component hook ergonomics

5 participants