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

Allow multiple component hooks for a given Component #12647

Closed
cBournhonesque opened this issue Mar 22, 2024 · 2 comments
Closed

Allow multiple component hooks for a given Component #12647

cBournhonesque opened this issue Mar 22, 2024 · 2 comments
Assignees
Labels
A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible X-Controversial There is active debate or serious implications around merging this PR

Comments

@cBournhonesque
Copy link
Contributor

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

It could be useful to have multiple component hooks for a given Component.
A usecase would be to allow libraries to create component-hooks that won't be overriden by the user.

For example, you could imagine bevy_ecs wanting to update change detection ticks via component hooks, while still allowing the user to define their own component hooks.

PROS:

  • increased flexibility
    CONS:
  • performance? we would have to store a Vec of hooks instead of just Option
  • how to guarantee an ordering between the hooks?

What solution would you like?

Letting ComponentHooks store multiple hooks of a given type (on_add, on_remove, etc.) for a component.

What alternative(s) have you considered?

  • Use observers? (not too familiar with them)
  • do not allow multiple hooks
@cBournhonesque cBournhonesque added C-Feature A new feature, making something new possible A-ECS Entities, components, systems, and events S-Needs-Triage This issue needs to be labelled X-Controversial There is active debate or serious implications around merging this PR labels Mar 22, 2024
@alice-i-cecile alice-i-cecile removed the S-Needs-Triage This issue needs to be labelled label Mar 22, 2024
@alice-i-cecile
Copy link
Member

Broadly in favor of this: I think that this is going to be a frustrating limitation for end users and third-party crate authors.

performance? we would have to store a Vec of hooks instead of just Option

We should use a SmallVec: I would expect one or two of these hooks at once usually.

@alice-i-cecile
Copy link
Member

@maniwani explained the design intent to me on Discord. Users are intended to use observers (#12231) to cover this use case, while component hooks are left to only the most fundamental setup/cleanup operations for the type.

adding a component would run the "on add" hook before running matching "on add" observers and removing a component would run matching "on remove" observers before running the "on remove" hook

@alice-i-cecile alice-i-cecile closed this as not planned Won't fix, can't repro, duplicate, stale Mar 23, 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-Feature A new feature, making something new possible X-Controversial There is active debate or serious implications around merging this PR
Projects
None yet
Development

No branches or pull requests

3 participants