Skip to content

Add new method entity_commands to EntityWorldMut#24266

Open
WeiTheShinobi wants to merge 1 commit into
bevyengine:mainfrom
WeiTheShinobi:add-entity_commands-method
Open

Add new method entity_commands to EntityWorldMut#24266
WeiTheShinobi wants to merge 1 commit into
bevyengine:mainfrom
WeiTheShinobi:add-entity_commands-method

Conversation

@WeiTheShinobi
Copy link
Copy Markdown

Objective

Fixes #23512
Added a shortcut for getting EntityCommands.

Hi, this is my first PR to Bevy, I’m not sure if my approach is developer want.
Thanks for the review!

@github-actions
Copy link
Copy Markdown
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide, as well as our policy regarding AI usage, and we look forward to reviewing your pull request shortly ✨

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

@kfc35 kfc35 added A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 12, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in ECS May 12, 2026
}

/// Creates a new [`EntityCommands`] instance that writes 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

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.

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

#[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

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-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

Add a method to get EntityCommands from EntityWorldMut

3 participants