-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Better API for Commands
methods that modify components
#1253
Comments
That would make it ambiguous if you wanted to insert a bundle of components or a single component that just so happens to have a type that could be a bundle too. |
Sadly a few of us tried that one way or another, without a nice success yet. There are hacky way abusing rust trait bounds, but nothing clean until we have at least negative trait bound stable I think |
(This is maybe not directly related or maybe more interesting for #1251) I would also suggest pulling the APIs of Alternatively (and I think the better option) would be to make commands more composable in general. And make it easier to create the "raw" commands ( fn spawn_my_button(button_text: String) -> impl Command {}
commands.add_command(spawn_my_button("Button text")); instead of fn spawn_my_button(commands: &mut Commands, button_text: String) {}
spawn_my_button(commands, "Button text"); But this requires a lot more design and I haven't really thought any of this through. |
As part of this, we need to remember to also change the API of |
Relevant: My bevy_ecs core rewrite (currently) looks like this for entity creation: world.spawn()
.insert_bundle(SomeBundle::default())
.insert(SomeComponent::default()); world.spawn() creates a new Entity and returns an EntityMut (which has insert_bundle, insert, remove_bundle, remove, etc) This has a number of benefits:
Imo entities are "collections of components", so insert/remove/get operations should be "component operations". Bundles are "higher level" constructs, so they need explicit terminology. |
My suggestions are as follows. Terminology:
|
Imo "add" is the wrong verb for the operation happening, especially in a rust context. "adding" is for adding something that was previously not a part of the object. "insert" in rust collections is an "upsert" (create or update), which is the operation that we perform for components / bundles. |
I like this, although I'm curious if it plays nice with
This is very much in line with my proposal of how we could get #1251 working, which is really nice :)
I agree with this pattern of thinking. The main challenge for me here is that while
Definitely think "insert" is the correct verb here. With the component-centric view, I also like keeping spawn and despawn around, because it indicates that something a little stranger is happening when you're operating on entities as a whole.
I like the change from "add_command" to "push", although see the discussion in #1251 and the event API in #1244 for more context :) |
This should be improved with #1562. |
Currently, we can modify components via Commands using
.insert
,.insert_one
,.remove
and.remove_one
.This is confusing to beginners, and makes the code less legible.
I suggest we rename these to
.insert_component
etc, to be more clear and sync up with.insert_resource
and friends.Are we also able to condense the bundle / single component versions of these in some way? I suspect the issue is similar to
query.get
andquery.get_component
, where there were small performance differences, but it would be a nice simplification.The text was updated successfully, but these errors were encountered: