-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Documentation strings for commands.rs - spawn, despawn, with, with_bundle, insert, insert_one #447
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
Conversation
…undle, insert, insert_one
cart
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for docs! This will definitely help new people learn how to use commands (which is a common issue)
| } | ||
|
|
||
| impl Commands { | ||
| /// Creates a new entity with a given component in the current [World]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect. This doesn't create an entity with a given component, but rather with a given DynamicBundle (which is a "set" of components).
It is worth showing two examples here: a spawn example using tuples:
commands.spawn((MyComponentA, MyComponentB))And an example using a derived Bundle
#[derive(Bundle)]
struct MyBundle {
a: MyComponentA,
b: MyComponentB,
}
commands.spawn(MyBundle {
a: MyComponentA,
b: MyComponentB,
})There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And lets call out that the two examples are equivalent.
| self.write_world(Despawn { entity }) | ||
| } | ||
|
|
||
| /// Describes an entity with an additional component. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets rephrase this to "Adds the given component to the current entity"
| self | ||
| } | ||
|
|
||
| /// Adds components to a already existing entity. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Adds a component bundle to an already existing entity"
| self.write_world(Insert { entity, components }) | ||
| } | ||
|
|
||
| /// Adds a single component to a already existing entity. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "an already"
…bundle doc, rewrote insert doc, rewrote insert_one doc
| /// # Example | ||
| /// ``` | ||
| /// // An example with only one component | ||
| /// commands.spawn(MyComponent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can't spawn single components like this. it must be a tuple. Can we replace it with:
commands.spawn((MyComponent,));Lets fix this in the other examples too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, damn. I was deceived by 'SpriteComponents' but it is a Bundle. I always wondered why there was a trailing 's'. Now I know. Should be fine now. (hopefully)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you arent the first person. I'm thinking about replacing the "_Components" suffix with "_Bundle" for clarity.
…ew users to watch out for it.
cart
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome lets merge this!
|
Ah first we need to resolve the formatting conflicts (you can see the suggested fixes in the build logs) Looks like you just need to remove the extra newlines from the docs. |
|
I believe it is not in my power to fix the remaining 5 build actions. Looks like the nightly version of rust is not installed successfully. |
|
I bet CI would succeed now. It's been a month of nightlies. 😄 |
|
Its interesting that That way we still get protection against breakage. |
|
The examples will need to be wrapped in some boilerplate since the code is still fully built with no_run and doc tests are treated as external to the current crate, e.g. /// Despawns only the specified entity, ignoring any other consideration.
/// # Example
/// ```no_run
/// # use bevy_ecs::{Commands, Entity};
/// # fn system(mut commands: Commands) {
/// # let entity_to_despawn = Entity::new(0);
/// commands.despawn(entity_to_despawn);
/// # }
/// ```
pub fn despawn(&mut self, entity: Entity) -> &mut Self {Another option is to use |
|
Cool then no-run w/ the additional boilerplate hidden seems like the right call |
|
Aye, I'm going to build some boilerplate then. I hope I get some spare time on my sunday. |
|
Is there a status update on this @eXodiquas? |
|
Closed in favor of #976 |
I wrote some documentation for the methods on Commands that I find myself using often. And as I started learning bevy those are methods I would have liked to just have a small example directly in the docs, so I made them. Let me know if something is not correct or if something could be written better. Maybe I wrote it too beginner friendly and lost some of the use cases of the methods that I have not encountered yet.
If someone tells me what the undocumented methods do, I'm happy to add those doc strings aswell. :)