-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Restore support for running fn EntityCommands on entities that might be despawned
#11107
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
|
What effect does using a closure for commands have here? Each instance of a closure is a unique type, but I'm not sure I understand how that would effect the performance or the amount of code generated. |
|
The closures shouldn't affect anything. They're just turning an explicit unique type into a hidden unique type. |
hymm
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.
alice-i-cecile
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.
I really like these changes. The reduced boilerplate is excellent.
IMO just completely removing things like the SpawnBatch struct from our public API is a net win: these were confusing and never used in practice.
# Objective - The `bundles` parameter in `insert_or_spawn_batch` method has inconsistent naming with docs (e.g. `bundles_iter`) since #11107. ## Solution - Replace `bundles` with `bundles_iter`, as `bundles_iter` is more expressive to its type.

Objective
In #9604 we removed the ability to define an
EntityCommandasfn(Entity, &mut World). However I have since realized thatfn(Entity, &mut World)is an incredibly expressive and powerful way to define a command for an entity that may or may not exist (fn(EntityWorldMut)only works on entities that are alive).Solution
Support
EntityCommands in the style offn(Entity, &mut World), as well asfn(EntityWorldMut). Use a marker generic on theEntityCommandtrait to allow multiple impls.The second commit in this PR replaces all of the internal command definitions with ones using
fndefinitions. This is mostly just to show off how expressive this style of command is -- we can revert this commit if we'd rather avoid breaking changes.Changelog
Re-added support for expressively defining an
EntityCommandas a function that takesEntity, &mut World.Migration Guide
All
Commandtypes inbevy_ecs, such asSpawn,SpawnBatch,Insert, etc., have been made private. Use the equivalent methods onCommandsorEntityCommandsinstead.If you were working with
ChildBuilder, recreate these commands using a closure. For example, you might migrate a Command to insert components like: