Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions crates/bevy_ecs/src/world/entity_access/world_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{
relationship::RelationshipHookMode,
resource::Resource,
storage::{SparseSets, Table},
system::EntityCommands,
template::{EntityScopes, ScopedEntities, Template, TemplateContext},
world::{
error::EntityComponentError, unsafe_world_cell::UnsafeEntityCell, ComponentEntry,
Expand Down Expand Up @@ -1877,6 +1878,17 @@ impl<'w> EntityWorldMut<'w> {
f(guard.entity_mut.world)
}

/// Creates a new [`EntityCommands`] instance that writes to the world's command queue
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this should explain that the commands are related to this EntityWorldMut's Entity, but I can't figure out the wording.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps something like:

Suggested change
/// Creates a new [`EntityCommands`] instance that writes to the world's command queue
/// Creates a new [`EntityCommands`] instance that writes commands
/// pertaining to this [`EntityWorldMut`]’s entity to the world's command queue

/// Use [`World::flush`] to apply all queued commands
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this new function is in EntityWorldMut, it seems more appropriate to reference EntityWorldMut’s version of flush.

Suggested change
/// Use [`World::flush`] to apply all queued commands
/// Use [`EntityWorldMut::flush`] to apply all queued commands

#[inline]
pub fn entity_commands(&mut self) -> EntityCommands<'_> {
let id = self.id();
EntityCommands {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks ok, but I wonder if the reborrow that happens in self.world().commands().entity(self.id()) works better / this way is preferred cause it is more succinct and relies on other written functions

I wouldn’t change anything as a result of this comment, just noting for anyone else reading

entity: id,
commands: self.world.commands(),
}
}

/// Updates the internal entity location to match the current location in the internal
/// [`World`].
///
Expand Down
Loading