Restore support for running fn EntityCommands on entities that might be despawned#11107
Merged
alice-i-cecile merged 4 commits intobevyengine:mainfrom Jan 8, 2024
Merged
Restore support for running fn EntityCommands on entities that might be despawned#11107alice-i-cecile merged 4 commits intobevyengine:mainfrom
fn EntityCommands on entities that might be despawned#11107alice-i-cecile merged 4 commits intobevyengine:mainfrom
Conversation
Contributor
|
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. |
Member
Author
|
The closures shouldn't affect anything. They're just turning an explicit unique type into a hidden unique type. |
hymm
approved these changes
Jan 7, 2024
alice-i-cecile
approved these changes
Jan 8, 2024
Member
alice-i-cecile
left a comment
There was a problem hiding this comment.
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.
mockersf
approved these changes
Jan 8, 2024
github-merge-queue bot
pushed a commit
that referenced
this pull request
Mar 31, 2024
# 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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: