Skip to content

Support component hooks closures #16371

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mnmaita
Copy link
Member

@mnmaita mnmaita commented Nov 13, 2024

Objective

Solution

  • Updated the Component macro to accept closures for ComponentHooks.

Testing

  • Compiled locally and tested by altering the component_hooks example.

@mnmaita
Copy link
Member Author

mnmaita commented Nov 13, 2024

I still have some outstanding questions regarding this change:

  • Is the example update any good? Or should I consider doing a "full rework" where we actually showcase the three ways of adding hooks to components in the actual code?
  • Should we consolidate RequiredFunc and HookFunc enums since they are essentially the same? I went for a simpler approach but was thinking on creating some DeriveFunc (or similar) to cover both cases and avoid code repetition.

@mnmaita mnmaita added A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward D-Macros Code that generates Rust code labels Nov 13, 2024
@hymm
Copy link
Contributor

hymm commented Dec 4, 2024

shouldn't this have the changes from bevy_ecs/src/components.rs in #12287 ?

Looking at the discussion in that pr, I'd vote not to support closures for hooks unless a user requests it. Fn can only borrow immutably, which doesn't feel like it adds much functionality here so I'm not sure how useful it would be.

@BenjaminBrienen BenjaminBrienen added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 22, 2025
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 D-Macros Code that generates Rust code D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants