-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Added App::with_component_hooks #16977
base: main
Are you sure you want to change the base?
Added App::with_component_hooks #16977
Conversation
Fixed CI failing because of unnecessary return type
You added a new example but didn't add metadata for it. Please update the root Cargo.toml file. |
…3-free/bevy into app-register-component-hooks
The generated |
…3-free/bevy into app-register-component-hooks
No complaints about the implementation, but I don't think we should do this. There's already too many methods on |
Is there a compromise where we can allow for mutably "inspecting" the app's world from an App, which would allow for keeping the builder-like construction of an App without API duplication? App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, trigger_hooks)
.inspect_world_mut(|world| world.with_component_hooks(...))
.init_resource::<MyComponentIndex>()
.add_event::<MyEvent>()
.run(); |
It feels like that method would make sense as |
Objective
app.world_mut().register_component_hooks()
, which is somewhat clunky. This PR aims to introduce a more concise way to add component hooks directly from the app interfaceSolution
on_add
,on_insert
, etc.) they want to add the hook to. Plus there's the issue of fallible hook add methods.with_children
on theEntityCommands
, passing a closure that will mutate the target (in this case --&mut ComponentHooks
) and return the parent, allowing it to chain nicely into the multitude of calls usually associated withApp
.Testing
with_component_hooks.rs
in theecs
section of examples. It works identically to thecomponent_hooks
example, but uses the new APIShowcase
While a showcase should aim to be brief and digestible, you can use a toggleable section to save space on longer showcases: