Skip to content
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

Component Hook functions as attributes for Component derive macro #13972

Open
ItsDoot opened this issue Jun 21, 2024 · 0 comments · May be fixed by #14005
Open

Component Hook functions as attributes for Component derive macro #13972

ItsDoot opened this issue Jun 21, 2024 · 0 comments · May be fixed by #14005
Labels
A-ECS Entities, components, systems, and events C-Usability A simple quality-of-life change that makes Bevy easier to use D-Macros Code that generates Rust code

Comments

@ItsDoot
Copy link
Contributor

ItsDoot commented Jun 21, 2024

What problem does this solve or what need does it fill?

To specify hooks for a type requires manually implementing Component currently. It would be nice to be able to specify hooks as derive attributes.

What solution would you like?

#[derive(Component)]
#[component(on_add = my_on_add_function, on_remove = my_on_remove_function)]
struct MyComponent {
    // ...
}

fn my_on_add_function(world: DeferredWorld, entity: Entity, component: ComponentId) {
    // ...
}


fn my_on_remove_function(world: DeferredWorld, entity: Entity, component: ComponentId) {
    // ...
}

What alternative(s) have you considered?

Currently requires manual trait implementation.

@ItsDoot ItsDoot added A-ECS Entities, components, systems, and events C-Usability A simple quality-of-life change that makes Bevy easier to use D-Macros Code that generates Rust code labels Jun 21, 2024
@ItsDoot ItsDoot changed the title Support specifying hook functions as attributes for Component derive macro Component Hook functions as attributes for Component derive macro Jun 21, 2024
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 simple quality-of-life change that makes Bevy easier to use D-Macros Code that generates Rust code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant